Vue component parent and child components pass reference type data

When writing the paging function today, I found that when the parent-child component passed the value, the child component could not monitor the change of the data in the parent component, and passed a reference type of data.

The reason is that the reference types share a memory address, and the parent and child components use the same object, so the child components cannot monitor changes. At this time, a deep copy needs to be made. The relevant code is as follows:

Actually param is a reference type

Make a deep copy of the value to be passed in the parent component, where self.pageDatasCopy is a deep copy of self.pageDatas, and self.pageDatas is a variable in the parent component,

Subcomponents monitor changes: (watch monitor)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324988397&siteId=291194637