vue2中使用@vue/vue-composition-api的一个问题

650 阅读1分钟

原因:由于项目中使用了ts(typescript)的方式去写逻辑,当安装完了vue-composition-api之后,

在main.ts中使用时,会出现如下的问题:

1mERROR in /var/lib/jenkins/workspace/CICD-libya-admin/src/main.ts
59:9 No overload matches this call.
  Overload 1 of 2, '(plugin: PluginObject<unknown> | PluginFunction<unknown>, options?: unknown): VueConstructor<Vue>', gave the following error.
    Argument of type '{ new (): Plugin; prototype: Plugin; }' is not assignable to parameter of type 'PluginObject<unknown> | PluginFunction<unknown>'.
      Property 'install' is missing in type '{ new (): Plugin; prototype: Plugin; }' but required in type 'PluginObject<unknown>'.
  Overload 2 of 2, '(plugin: PluginObject<any> | PluginFunction<any>, ...options: any[]): VueConstructor<Vue>', gave the following error.
    Argument of type '{ new (): Plugin; prototype: Plugin; }' is not assignable to parameter of type 'PluginObject<any> | PluginFunction<any>'.
      Property 'install' is missing in type '{ new (): Plugin; prototype: Plugin; }' but required in type 'PluginObject<any>'.

,使的项目无法启用并进行操作,在网上搜索了相关之后,最终在一个链接处找到

如截图:

目录:

node_modules=》@vue=>vue-composition-api=>dist/vue-composition-api.d.ts这个文件

找到第138行(位置都可以的,并不一定是第138行)的位置,如截图:

declare const  Plugin:{
    install:(Vue:VueConstructor)=>void
}

复制放到

node_modules=》@vue=>vue-composition-api=>dist/vue-composition-api.d.ts这个文件

并重启项目即可使用,若未使用ts的话,就不用这个步骤了,

直接在main.js中导入即可,如下代码:

import Vue from "vue";
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)