Typescript Vue.JS:TS2339:Property'';不存在于类型';{组成部分:{
我将Vue与单个文件组件一起使用(实际上,我试图将这些.Vue组件拆分为3个不同的文件,.Vue具有脚本和样式标记,每个标记都调用一个单独的文件) 但在此文件中:Typescript Vue.JS:TS2339:Property'';不存在于类型';{组成部分:{,typescript,vue.js,Typescript,Vue.js,我将Vue与单个文件组件一起使用(实际上,我试图将这些.Vue组件拆分为3个不同的文件,.Vue具有脚本和样式标记,每个标记都调用一个单独的文件) 但在此文件中: import modelsList from '@/components/modelsList/modelsList.vue'; import bookerService from '@/services/booker.ts'; export default { components: { modelsList },
import modelsList from '@/components/modelsList/modelsList.vue';
import bookerService from '@/services/booker.ts';
export default {
components: { modelsList },
data: function() {
return {
homeModels: [] as any[],
};
},
created: function() {
this.homeModels = bookerService.getHomeModels();
},
};
我收到了错误消息:
TS2339:类型{组件:{
modelsList:VueConstructor;};数据:()=>{homeModels:any[];
};已创建:()=>void;}'
你知道这里发生了什么吗
还有一个小问题,你知道为什么如果我不在导入中添加文件扩展名,会出现如下错误:
找不到模块“@/components/modelsList/modelsList”或其相应的类型声明
这是我的tsconfig.json:
{
"compilerOptions": {
"target": "esnext",
"strict": true,
"module": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"removeComments": true,
"sourceMap": true,
"paths": {
"@/*": [
"assets/vue/*"
]
},
"esModuleInterop": true,
"jsx": "preserve",
"importHelpers": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"types": [
"webpack-env"
],
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"files": [
"assets/vue/vue-shims.d.ts"
],
"exclude": [
"node_modules"
]
}
好的,我们刚刚发现tsconfig.json的“include”数组中有一个错误:
{
"compilerOptions": {
"target": "esnext",
"strict": true,
"module": "esnext",
"moduleResolution": "node",
"baseUrl": "./",
"removeComments": true,
"sourceMap": true,
"paths": {
"@/*": [
"assets/vue/*"
]
},
"esModuleInterop": true,
"jsx": "preserve",
"importHelpers": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"types": [
"webpack-env"
],
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"files": [
"assets/vue/vue-shims.d.ts"
],
"exclude": [
"node_modules"
]
}
必须将每个include的“src/”父文件夹替换为我的vue项目的真实文件夹,相对于tsconfig.json,这对我来说是“assets/vue/”。您使用的是哪个版本的vue?