recently I encountered two problems in learning Vue2,:
The property of1.data is an object. Setting the property value of the object directly through assignment should not update the view, but if you set the value of another property of data, it will cause the view update and the view update of this object at the same time.
<div id="app">
<div>
{{message}}
</div>
<div>
{{object.name}}
</div>
</div>
var vm = new Vue({
el: "-sharpapp",
data(){
return {
message: "message",
object: {}
}
}
});
// vm.$set(vm.object, "name", "setobject");
// , ,
vm.object.name = "object";
// , !
//vm.message = "message";
// vm.$forceUpdate();
2.setTimeout, even though there is no view update via Vue.set
<div id="app">
<div>
{{message}}
</div>
<div>
{{object.name}}
</div>
</div>
var vm = new Vue({
el: "-sharpapp",
data(){
return {
message: "message",
object: {}
}
}
});
// , setTimeout
// vm.$set(vm.object, "name", "object");
vm.object.name = "set, object";
setTimeout(function(){
//
vm.$set(vm.object, "name", "setobject");
// vm.$forceUpdate();
}, 500);
I do not know whether the description is clear, please take a look at it (no Baidu), thank you!