我使用TypeScript创建了一个vue组件,并在
和在
Property 'xxx' does not exist on type 'CombinedVueInstance>>'.
例如:
33:18 Property 'open' does not exist on type 'CombinedVueInstance>>'.
31 | methods: {
32 | toggle: function () {
> 33 | this.open = !this.open
| ^
34 | if (this.open) {
35 | // Add click listener to whole page to close dropdown
36 | document.addEventListener('click', this.close)
此错误还显示任何时间
使用了。
这是组件:
import Vue from 'vue';
import axios from 'axios'
export default Vue.extend({
data: function () {
return {
open: false
}
},
computed: {
profilePath: function () {
return "/user/" + this.$store.state.profile.profile.user.id
}
},
methods: {
toggle: function () {
this.open = !this.open
if (this.open) {
// Add click listener to whole page to close dropdown
document.addEventListener('click', this.close)
}
},
close: function () {
this.open = false;
document.removeEventListener('click', this.close)
}
}
})
是什么导致了这个错误?它似乎仍然在开发中使用错误,但当我部署到生产环境中时,它们会导致问题。
发布于 2019-08-27 23:47:50
中提到的
Typescript支持
部分的Vue文档:
由于Vue声明文件的循环性质,TypeScript可能难以推断某些方法的类型。因此,您可能需要在render和computed等方法上注释返回类型。
在你的情况下,你应该改变
至
如果您有一个render()方法返回值,而不是返回值,那么您可能会遇到同样的错误
注释。
发布于 2019-05-07 16:38:49
这似乎是由于使用
计算的返回值
,并在其声明中使用未指定的返回类型。
一种解决方法是将返回类型指定为
profilePath: function(): string {
已验证
和
__,在macOS Mojave上使用Vue CLI3.7.0
GitHub演示
发布于 2020-07-09 15:59:28
这里描述了同样的问题
https://www.gitmemory.com/issue/vuejs/vue/9873/485481541
因为这是TS 3.4.x的一个问题,3.9.6现在对我来说工作得很好
https://stackoverflow.com/questions/56002310
复制相似问题