【发布时间】:2022-01-03 17:41:16
【问题描述】:
我正在生成一个运行良好的页面列表,我想添加一个可以根据类别查询对象的类别列表。对于带有节点的页面,这是我在 gridsome.server.js 中所做的:
data.django.jobOfferList.edges.forEach(({ node }) => {
createPage({
path: `/${node.category}/${node.id}`,
component: "./src/templates/JobOfferTemplate.vue",
context: {
id: node.id,
},
});
}
这与以下名为 JobsListSection.vue 的部分完美配合:
<template>
<section class="section">
<h1 class="title">Nos offres d'emploi</h1>
<div class="columns is-multiline">
<JobOfferCard
v-for="(edge, index) in $static.django.jobOfferList.edges"
:key="index"
:content="edge.node"
/>
</div>
</section>
</template>
<static-query>
query retrieveAllOffersByReverseChronology {
django {
jobOfferList(orderBy: "-created_at") {
edges {
node {
id
description
company
category
active
createdAt
title
}
}
}
}
}
</static-query>
<script>
import JobOfferCard from "@/components/JobOfferCard.vue";
export default {
name: "JobsListSection",
components: { JobOfferCard },
};
</script>
现在,我尝试创建基于类别的模板;这是我在gridsome.server.js 中添加它的方式:
createPage({
path: `/${node.category}`,
component: "./src/templates/JobsCategoryListSection.vue",
context: {
category: node.category,
},
});
我们可以看到我传递了一个名为category 的参数;但是当我在我的模板中查询它时:
<static-query>
query ($category: String) {
django {
jobOfferList(category_Icontains: $category) {
edges {
node {
id
description
company
category
active
createdAt
title
}
}
}
}
}
</static-query>
我收到以下错误:
Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/static-query.js):
Error: Variable "$category" of required type "String!" was not provided.
我不明白为什么它无法检测到我传递的变量类别。我的代码有问题吗?
【问题讨论】:
标签: javascript node.js graphql gridsome