【发布时间】:2021-06-10 12:54:21
【问题描述】:
我遇到了一个问题,当我尝试通过 compted 属性访问对象的属性时,它是未定义的。对象设置为异步。
有两点需要澄清:
1- 当我将对象记录到计算函数内的控制台时-> 属性(状态)已设置。但是当我记录属性本身时,它是未定义的。
computed: {
propA() {
console.log(this.booking);
// { state: "Draft", product: (...) }
console.log(this.booking.state);
//undefined
console.log(this.booking.product);
//"Product abc"
}
}
2- this.booking.state 通过v-model 正确绑定到视图。
booking设置如下:
props: {
currentBooking: Object,
},
data() {
return {
booking: Object,
};
},
async mounted() {
this.booking = { ...this.currentBooking }; // {product: "Product abc"}
this.booking.state = "Draft";
}
【问题讨论】:
-
booking属性是如何定义的? -
你试过 vue 开发工具了吗?有什么分析可以提吗?
-
我已经更新了问题
标签: vue.js