问题:checkbox默认全选之后 再点击的时候页面没有效果
之前的错误写法
this.list[i].checked = true
改正之后
this.$set(this.list[i], ‘checked’, true)
this.$http.post(this.urlList, params).then((res) => {
if (res.data.success) {
let result = res.data.result
this.led = result
const arr = result.goodsList
this.list = arr
for (let i = 0; i < this.list.length; i++) {
this.$set(this.list[i], 'checked', true)
}
}
顺便记录一下vue 中 set 的使用方法
Vue.set( target, propertyName/index, value )
参数:
{Object | Array} target
{string | number} propertyName/index
{any} value
返回值:设置的值。
用法:
向响应式对象中添加一个 property,并确保这个新 property 同样是响应式的,且触发视图更新。它必须用于向响应式对象上添加新 property,因为 Vue 无法探测普通的新增 property (比如 this.myObject.newProperty = ‘hi’)
注意对象不能是 Vue 实例,或者 Vue 实例的根数据对象。