在计算属性中依赖于props的data数据,当data更新后,computed并没有实时去拿data数据。(本来想通过watch data的改变去实现,但是watch一直不执行,但data数据本身确实改变了,很诡异...)
代码如下:
props: {
data: {
default: () => {},
type: Object,
},
},
data() {
return {
};
},
created() {
},
computed: {
...mapState({
}),
handleTotalPrice() {
return this.fixNumber(this.totalPrice);
},
handledData() {
const handledData = JSON.parse(JSON.stringify(this.data)); // 这里
Object.entries(handledData).forEach(([key, value]) => {
if (value.price) {
handledData[key].price = this.fixNumber(value.price);
}
if (value.list) {
...
}
});
return handledData;
|