Plugins 请告诉我如何编写nuxt插件;打印d';

Plugins 请告诉我如何编写nuxt插件;打印d';,plugins,nuxt.js,Plugins,Nuxt.js,在开发过程中,我们使用Printd实现了要打印的页面 创建插件/printd.ts import Vue from "vue"; import { Printd } from "printd"; Vue.use(Printd); nuxt.conifg.ts的“插件”部分 plugins: [ ... , { src: "~/plugins/printd", ssr: false }] 但错误如下所示 10:9 No overload matches this call. Overlo

在开发过程中,我们使用Printd实现了要打印的页面

创建插件/printd.ts

import Vue from "vue";
import { Printd } from "printd";

Vue.use(Printd);
nuxt.conifg.ts的“插件”部分

plugins: [
... ,
{ src: "~/plugins/printd", ssr: false }]
但错误如下所示

10: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 'typeof Printd' is not assignable to parameter of type 'PluginObject<unknown> | PluginFunction<unknown>'.
      Property 'install' is missing in type 'typeof Printd' 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 'typeof Printd' is not assignable to parameter of type 'PluginObject<any> | PluginFunction<any>'.
      Property 'install' is missing in type 'typeof Printd' but required in type 'PluginObject<any>'.
     8 | 
     9 | 
  > 10 | Vue.use(Printd);
       |         ^
    11 | 
10:9没有重载与此调用匹配。
重载1/2'(plugin:PluginObject | PluginFunction,options?:未知):VueConstructor',出现以下错误。
类型为“typeof Printd”的参数不能分配给类型为“PluginObject | PluginFunction”的参数。
类型“typeof Printd”中缺少属性“install”,但类型“PluginObject”中需要属性“install”。
重载2/2'(plugin:PluginObject | PluginFunction,…选项:any[]):VueConstructor',出现以下错误。
类型为“typeof Printd”的参数不能分配给类型为“PluginObject | PluginFunction”的参数。
类型“typeof Printd”中缺少属性“install”,但类型“PluginObject”中需要属性“install”。
8 | 
9 | 
>10 | Vue.使用(打印d);
|         ^
11 | 
救救我

这对我很有用:

import Vue from "vue"
import { Printd } from "printd";

Vue.prototype.$Printd = new Printd();
然后您可以在整个应用程序中访问此$Printd

试着添加:就像下面一样

import Vue from "vue";
import { Printd } from "printd";

Vue.use(Printd as any);
这可能是你的答案。但如果这不起作用,试试这个

import Vue from "vue";
const Printd = require("printd").Printd;

Vue.use(Printd);
。。。如果这仍然不起作用,试试这个。 文件:~/types/index.d.ts

declare module "printd"

plugins/printd.ts``从“printd”导入{printd};const d=新打印的d();导出默认值d;`改变