javascript - Apollo 不可分配给“VueClass”类型的参数
问题描述
我正在用打字稿构建一个“Nuxt.js”应用程序。
这是我的代码:
<script lang='ts'>
import {Component, Vue} from 'nuxt-property-decorator';
import {LOCATION} from '~/constants/graphql/location';
@Component({
apollo: {
getLocation: {
query: LOCATION,
variables(): object {
return {
id: 10,
};
},
prefetch: true,
},
},
})
export default class Home extends Vue {
}
</script>
我收到以下错误:
Argument of type '{ apollo: { getLocation: { query: any; variables(): object; prefetch: boolean; }; }; }' is not assignable to parameter of type 'VueClass<Vue>'.
Object literal may only specify known properties, and 'apollo' does not exist in type 'VueClass<Vue>'.
我知道这是来自 TS 但如何解决?
解决方案
您列出的“apollo”选项的语法看起来确实正确 - 假设您打算使用包“vue-apollo”来使用 Apollo。
如果您收到此错误,则可能意味着“vue-apollo”尚未安装,或者安装有问题。
如果您在其中一个页面上查看 Vue Chrome 调试器工具,是否所有组件中都存在“$apollo”属性?如果没有,问题是“vue-apollo”插件没有正确安装。
推荐阅读
- php - SQL Query echo loop in 2 html table colums
- python - 使用导入脚本填充数据库表 - django
- jquery - 我想通过更改文本来更改课程
- python - 使用 re.sub() 查找和替换多个字符串
- regex - 使用 sed 的未终止地址正则表达式
- c# - 在 C# 中从 Go 调用函数
- javascript - 迭代元素并替换新 ID 并将 ID 用于其他 div 中的属性
- android - 如何在 VSC 中运行和调试 React Native Android App?
- c - 由于 int,我无法打印出 A02 而不是 A2
- r - 如何在 dplyr group_by 中使用自定义函数