比如,有一个checkList
数组,在computed
中重写它的get
和set
computed() {
checkList: {
get() {
//return 一个值
}
set(newVal) {
}
}
}
具体项目中
<el-form-item label="服务保证:">
<el-checkbox-group v-model="checkList">
<el-checkbox :label="1">无忧退货</el-checkbox>
<el-checkbox :label="2">快速退货</el-checkbox>
<el-checkbox :label="3">免费包邮</el-checkbox>
</el-checkbox-group>
</el-form-item>
checkList: {
get() {
if (this.value && this.value.serviceIds && this.value.serviceIds.length > 0) {
let list = this.value.serviceIds.split(',').map(item => Number(item))
return list
} else {
return []
}
},
set(newVal) {
if (newVal && newVal.length > 0) {
this.value.serviceIds = newVal.join(',')
} else {
this.value.serviceIds = null
}
}
}