Vue新手。
使用vue-property-decorator &也尝试了vue-class-component。
根据github (https://github.com/kaorun343/vue-property-decorator)的说法,data对象是在类中明确声明的,例如ecosystem
import {Component, Vue} from 'vue-property-decorator';
@Component({
components: {}
})
export default class HelloWorld extends Vue {
ecosystem: [
{
text: 'vuetify-loader',
href: 'https://github.com/vuetifyjs/vuetify-loader'
},
{
text: 'github',
href: 'https://github.com/vuetifyjs/vuetify'
},
{
text: 'awesome-vuetify',
href: 'https://github.com/vuetifyjs/awesome-vuetify'
}
]
}而不是
data() {
return {
ecosystem: ['bla', 'bla', 'bla']
}
}但是,当我尝试使用它时,收到错误Property or method "ecosystem" is not defined on the instance but referenced during render.
呼叫到
created() {
console.log(this.ecosystem)
}还返回undefined
我遗漏了什么?
发布于 2018-12-19 04:37:49
请参阅运行示例:https://codesandbox.io/s/y2nop643xv
像这样声明生态系统:
ecosystem: any = [
{
text: "vuetify-loader";
href: "https://github.com/vuetifyjs/vuetify-loader";
},
{
text: "github";
href: "https://github.com/vuetifyjs/vuetify";
},
{
text: "awesome-vuetify";
href: "https://github.com/vuetifyjs/awesome-vuetify";
}
];还有一个小技巧,尽量避免使用任何,你正在使用typescript,使用类型化的对象
https://stackoverflow.com/questions/53840229
复制相似问题