Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将CoreUI图标导入Vue.js TypeScript项目_Typescript_Vue.js_Icons_Core Ui - Fatal编程技术网

将CoreUI图标导入Vue.js TypeScript项目

将CoreUI图标导入Vue.js TypeScript项目,typescript,vue.js,icons,core-ui,Typescript,Vue.js,Icons,Core Ui,我正在用TypeScript中的CoreUI构建一个Vue.js应用程序。 我目前遇到的问题与CoreUI的图标有关。我的应用程序运行良好并呈现图标,但VSC抱怨具体行: icons: { cilHome, cilSettings }, 以下是我的main.ts的全部代码: import Vue from "vue"; import App from "./App.vue"; import CoreuiVue from "@coreui/vue"; import { cilPencil, ci

我正在用TypeScript中的CoreUI构建一个Vue.js应用程序。 我目前遇到的问题与CoreUI的图标有关。我的应用程序运行良好并呈现图标,但VSC抱怨具体行:

icons: { cilHome, cilSettings },
以下是我的main.ts的全部代码:

import Vue from "vue";
import App from "./App.vue";
import CoreuiVue from "@coreui/vue";
import { cilPencil, cilSettings } from "@coreui/icons";
import router from "./router";
import store from "./store";

Vue.config.productionTip = false;

Vue.use(CoreuiVue);

new Vue({
  router,
  store,
  icons: { cilPencil, cilSettings },
  render: h => h(App)
}).$mount("#app");
VSC错误文本:

没有与此调用匹配的重载。 重载第1个,共3个“”(选项?:ThisTypedComponentOptions WithArrayProps |未定义):CombinedVueInstance>”,出现以下错误。 类型为“{router:VueRouter;store:store;icons:{cilHome:string[];cilSettings:string[];};render:(h:CreateElement)=>VNode;}”的参数不能分配给类型为“ThisTypedComponentOptions WithArrayProps”的参数。 对象文字只能指定已知属性,并且“ThisTypedComponentOptions WithArrayProps”类型中不存在“图标”。 重载3个选项中的第2个’(选项?:ThisTypedComponentOptions WithRecordProps |未定义):CombinedVueInstance>”,出现以下错误。 类型为“{router:VueRouter;store:store;icons:{cilHome:string[];cilSettings:string[];};render:(h:CreateElement)=>VNode;}”的参数不能分配给类型为“ThisTypedComponentOptions WithRecordProps”的参数。 对象文字只能指定已知属性,并且“ThisTypedComponentOptions WithRecordProps”类型中不存在“图标”。 重载3/3’(选项?:ComponentOptions,DefaultMethods,DefaultComputed,PropsDefinition>,Record>| undefined):CombinedVueInstance’给出了以下错误。 类型为“{router:VueRouter;store:store;icons:{cilHome:string[];cilSettings:string[];};render:(h:CreateElement)=>VNode;}”的参数不能分配给类型为“ComponentOptions,DefaultMethods,DefaultComputed,PropsDefinition>,Record>”的参数。 对象文字只能指定已知属性,并且“ComponentOptions、DefaultMethods、DefaultComputed、PropsDefinition>、Record>”类型中不存在“图标”。ts(2769) 偷窥问题 没有可用的快速修复方法

我假设这是一个TypeScript类型的问题,因为代码在EcmaScript中构建时没有任何问题:。
如果您能分享您在这些问题上的经验,我将不胜感激。谢谢大家!

通过创建自定义类型文件xxx.d.ts,我能够解决该错误:

import Vue, { ComponentOptions } from "vue";

declare module "vue/types/options" {
  interface ComponentOptions<V extends Vue> {
    icons?: any;
  }
}
从“Vue”导入Vue,{ComponentOptions};
声明模块“vue/类型/选项”{
接口组件选项{
图标?:任何;
}
}

您是在哪里创建的,是如何导入的?@LakShan,我在“src”中创建了一个文件夹“custom types”,并将此文件放入其中。TypeScript会自动拾取,不会出现任何问题。因此,不需要进口。