我正在使用打字稿构建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>'.
对象文字只能指定已知的属性,并且'apollo'在'VueClass'类型中不存在。
我知道它来自TS,但如何解决?
答案 0 :(得分:1)
@Component接受VueClass类型的参数,这些项目需要是道具,组件,方法等。例如:
@Component({
components: {
HelloWorld
}})
答案 1 :(得分:0)
使用以下方法更新您的tsconfig.json
:
"strictFunctionTypes": false
答案 2 :(得分:0)
您列出的“ apollo”选项的语法确实看起来正确-假设您打算使用软件包“ vue-apollo”与Apollo一起使用。
如果遇到此错误,则可能意味着尚未安装“ vue-apollo”,或者安装存在问题。
如果您在其中一页上的Vue Chrome调试器工具中查看,“ $ apollo”属性是否存在于所有组件中?如果不是,则问题是“ vue-apollo”插件未正确安装。