(Vue.set)无知的我又被坑了

78 阅读1分钟

今天在使用vue时,遇到一个情况:

this.detail.cx_product_list = res.value;
console.log(this.detail.cx_product_list); //cx_product_list 是有值的
但是html中detail.cx_product_list.length 就是一直报错!!!

原来:原始detail中没有cx_product_list;那么后面我赋值那一步虽然成功了但是在vue中
没有生成 getset方法。

正确写法: Vue.set( this.detail , 'cx_product_list' , res.value)