Vue data changes, force view update

 Vue change in data, forcing view updates, view does not update the causes and solutions

 

Option 1, with Object.assign

Object changes: oldObj = Object.assign ({}, newobj);

Principle: The object is a reference type, direct change a property oldObj point address has not changed, vue may not be able to monitor, so when we create a new object and assign oldObj field, then changed its points directly address

 

Option 2, with vue.set

Objects and arrays can be used

this.$set(this,'oldObj',newObj);
this.$set(this,'oldArray',newArray);

For example, to change the data in some: {name: {a: , b 1: 3}} values of b which can be so

this.$set(this.some.name,‘b’,2)

Vue allowed dynamically adding a new root level responsive properties on the instance has been created, but it may be used to add the appropriate attributes vue.set method to the nested object.

 

Option 3, use update

the this. $ forceUp DATE (), force view update

 


----------------
Disclaimer: This article is CSDN blogger "tangdou5682 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/tangdou5682/article/details/99946515

Guess you like

Origin www.cnblogs.com/Antwan-Dmy/p/12566670.html