这很奇怪,但很简单:
我有一个来自b-nav
的导航栏bootstrap-vue
,我要在其中填充动态b-nav-item
。我的vuejs组件的模板如下所示:
<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查询时,它也会正确返回所需的数据。我承认这次我不知道在哪里看..
好吧,几个小时后我突然有了某种照明,我注意到我不知道的某些东西:
[用阿波罗填充数据时,我们将数据放入其中的变量必须带有在下面称为查询的名称。
所以我试图做:apollo: { applications: INSTALLED_APPLICATIONS_QUERY }
而我的查询是:
const INSTALLED_APPLICATIONS_QUERY = gql`
query {
installedApplications {
id
verboseName
}
}
`
所以我要做的是apollo: { installedApplications: INSTALLED_APPLICATIONS_QUERY }
。我没有意识到这一点,而且很有趣的是,我在所有其他组件中都在不知不觉中做到了。