我正在使用React Starter Kit ,我试图将一个字符串与查询一起作为参数传递,但没有任何效果。我尝试了以下方法:
export default {
path: '/',
async action() {
const resp = await fetch('/graphql', {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `{
posts {
id,
title,
content,
date
},
page(slug: 'homepage'){
id,
date,
modified,
slug,
type,
title,
content,
excerpt,
author
}
}`,
}),
credentials: 'include',
});
const { data } = await resp.json();
console.log('in home/index');
if (!data || !data.posts) throw new Error('Failed to load the homepage.');
return {
title: 'React Starter Kit',
component: <Layout><Home posts={data.posts} page={data.page} /></Layout>,
};
},
};
但是每次我包含括号时它都会失败......传递参数的正确方法是什么?