首页 > 解决方案 > 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 但如何解决?

标签: javascripttypescriptvue.jsapollonuxt.js

解决方案


您列出的“apollo”选项的语法看起来确实正确 - 假设您打算使用包“vue-apollo”来使用 Apollo。

如果您收到此错误,则可能意味着“vue-apollo”尚未安装,或者安装有问题。

如果您在其中一个页面上查看 Vue Chrome 调试器工具,是否所有组件中都存在“$apollo”属性?如果没有,问题是“vue-apollo”插件没有正确安装。


推荐阅读