问题描述:
有天在使用uniapp获取数据时出现了当获取数据后无法修改数据里面的值,但是在控制台打印的时候又可以打印出数据,例如: const res = await get('v1/product/GetOne', { productID: option.productID });
this.product = res.data.rows
// 获取到的(res.data.rows)赋值给 this.product 打印 this.product 可以得到一个对象{...}
// 对象里面有一个 isPlanB 属性
// 当我想改变isPlanB 的值时,isPlanB 修改不了
this.product.isPlanB = false;
// 这样修改发现没效果 之后就开始了百度之旅
解决方案:
使用eval(),将获取的对象进行类型转换,把值类型转换成引用类型 就可以解决 const res = await get('v1/product/GetOne', { productID: option.productID });
var product2 = eval(res.data.rows)
this.product = product2
this.product.isPlanB = false;