Mar*_*nen 6 typescript vue.js visual-studio-code
VS Code 在编辑我的 Vue Typescript 文件时报告了很多问题/红线:
示例错误:
[ts] Property 'isLoading' does not exist on type 'CombinedVueInstance<Vue,
object, > object, object, Readonly<Record<never, any>>>'. [2339]
Run Code Online (Sandbox Code Playgroud)
当我在“this”上引用一个属性时,问题似乎出现了,并且所有此类引用在编辑器中都有一条红线,说明上述错误的一个变体。对于 Vue 的数据对象中定义的属性和方法中定义的函数,问题都是一样的。
现在,有两个有趣的方面:
关于我的设置的信息:
tsconfig.js:
{
"compilerOptions": {
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"allowJs": true,
"target": "es5",
"strict": true,
"module": "es6",
"moduleResolution": "node",
"outDir": "../../../dist/public/js",
"sourceMap": true
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
我现在完全被难住了 - 希望有人能帮助我......
下面的代码示例(所有这些。参考在我的 VS 代码中有一条红线):
import axios from "axios";
import Vue from "vue";
// tslint:disable-next-line no-unused-expression
new Vue({
computed: {
hasProvider(): boolean {
// this line throw two errors
return this.isLoading === false && this.providerList.length > 0;
},
},
data() {
return {
description: "",
id: "",
isLoading: true,
name: "",
providerList: [],
};
},
el: "#app",
methods: {
loadProviderList() {
axios
.get("/api/provider/all")
.then((res: any) => {
// these lines throw an error
this.providerList = res.data.items;
this.isLoading = false;
})
.catch((err: any) => {
// tslint:disable-next-line:no-console
console.log(err);
});
}
},
mounted() {
// this line throw an error
return this.loadProviderList();
}
});
Run Code Online (Sandbox Code Playgroud)
小智 6
在settings.json中设置:
"vetur.experimental.templateInterpolationService": false
Run Code Online (Sandbox Code Playgroud)
Mar*_*nen -1
问题似乎出在我的 Mounted() 阶段的 return 语句上。删除该返回(可能是我使用的示例中剩下的东西)解决了问题。
mounted() {
// this works
this.loadProviderList();
}
Run Code Online (Sandbox Code Playgroud)
尽管如此,奇怪的是环境一天又一天地改变了行为,并且它编译了 - 可能永远不会得到答案:)
归档时间: |
|
查看次数: |
7233 次 |
最近记录: |