vue neutron components directly modify the parent component attribute prop bug

In some cases, sub-assemblies directly modify the parent component coming from prop 对象the property of sync problems.

For example, the parent component pass over an object checkBoxObj:

checkBoxObj:{
    checked: false
}

The checkedbinding by v-model to sub-assemblies checkbox, then click the checkbox, trying to change the checkedvalues, but sometimes find the opposite checkbox is checked and checked, that is, the problem is not synchronized.

(Try to) solution

The prop's checkBoxObjvalue is assigned to a value of the data checkBoxData,

this.checkBoxData = this.checkBoxObj;

Because it is a direct assignment, there are also references to the relationship, modify checkBoxDatathe checkedequivalent modify checkBoxObjthe checked. So this bug does not occur.

Then simply edit the checked property value checkBoxData, do not directly modify the value prop pass over.

Guess you like

Origin www.cnblogs.com/lvonve/p/11994254.html