Apollo不可分配给'VueClass <Vue>类型的参数

Fil*_*ski 6 javascript typescript apollo vue.js nuxt

我正在使用打字稿构建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>
Run Code Online (Sandbox Code Playgroud)

我有错误:

Argument of type '{ apollo: { getLocation: { query: any; variables(): object; prefetch: boolean; }; }; }' is not assignable to parameter of type 'VueClass<Vue>'.
Run Code Online (Sandbox Code Playgroud)

对象文字只能指定已知的属性,而'apollo'在'VueClass'类型中不存在。

我知道它来自TS,但如何解决?

小智 0

@Component 接受 VueClass Type 的参数,项目需要是 props、组件、方法等。例如:

@Component({

  components: {

    HelloWorld

}})
Run Code Online (Sandbox Code Playgroud)