The reason why the el-checkbox state value is modified but the style is not modified

The reason why the el-checkbox state value is modified but the style is not modified

First of all, it is a pit encountered by the recent project

The requirement is: I first adjust the interface to obtain the label values ​​of all unselected checkboxes and render them, and then adjust the interface to obtain the selected checkboxes and render them to the page. After that, I can modify whether to cancel the checkbox select

Problem: After calling the interface, the page is rendered and selected, but I cannot modify the state of the checkbox again, but the checked state of the printed value has changed

The original approach:

// 调用接口后给每一项已选择的对象添加一个checked:true的属性及值,checked是在checkbox中判断是否选择
oneItem.checked = true;

Cause of error: The array is modified, and the data is not bidirectionally bound, so my subsequent modification can no longer change its state

Revise:

// 使用$set, 进行双向绑定
this.$set(oneItem, "checked", true);

Above, checked can be initialized selectively, and can be modified normally later

Guess you like

Origin blog.csdn.net/qq_51741730/article/details/126845764