这很奇怪,但很简单:
我有一个来自bootstrap-vue的导航条bootstrap-vue,我想在其中填充动态b-nav-items。
<template>
<b-nav vertical class="px-2">
<b-nav-item
v-for="application in applications"
:key="application.id"
to="#">
{{ application.verboseName }}
</b-nav-item>
<b-nav-item :to="{ name: 'BaseSettings' }">
<font-awesome-icon :icon="['fas', 'cogs']" class="fa-fw mr-1"/>
Settings
</b-nav-item>
</b-nav>
</template>第二个b-nav-item是静态的,但是第一个应该用applications动态填充,我在组件中检索的如下所示:
<script>
// ...
apollo: { applications: INSTALLED_APPLICATIONS_QUERY },
// ...
</script>问题是它根本不起作用。我已经完成了使用graphql在其他组件中检索内容的其他列表,并且它工作得很好。此外,当我试图提供一些本地数据来测试它时:
data () {
return {
apps: [ // used for tests
{ id: '1', verboseName: 'Test1' },
{ id: '2', verboseName: 'Test2' },
{ id: '3', verboseName: 'Test3' },
{ id: '4', verboseName: 'Test4' }
]
}
}<b-nav vertical class="px-2">
<b-nav-item
v-for="application in apps"
:key="application.id"
to="#">
{{ application.verboseName }}
</b-nav-item>
...
</b-nav>它工作得很完美..。当我在我的应用程序的/graphql接口上尝试我的graphql查询时,它也正确地返回了所需的数据。我承认这一次我不知道该去哪看..。
发布于 2020-02-05 08:22:54
好吧,几个小时后我突然发现了一些我不知道的东西:
当使用阿波罗填充数据时,我们放置数据的变量必须使用下面调用的查询的名称。
所以我试着做:apollo: { applications: INSTALLED_APPLICATIONS_QUERY },而我的查询是:
const INSTALLED_APPLICATIONS_QUERY = gql`
query {
installedApplications {
id
verboseName
}
}
`所以我要做的是apollo: { installedApplications: INSTALLED_APPLICATIONS_QUERY }。我没有意识到这一点,很有趣的是,在我所有的其他组件中,我无意识地做了这件事。
https://stackoverflow.com/questions/60071254
复制相似问题