Home > Web Front-end > JS Tutorial > body text

How to treat deep copy in vue

亚连
Release: 2018-06-08 18:24:50
Original
2115 people have browsed it

This article mainly introduces the relevant information about vue deep copy. It is very good and has reference value. Friends who need it can refer to it

The Object.assign() method is used to assign all enumerable attributes. Values ​​are copied from one or more source objects to the target object. It will return the target object.

const object1 = {
a: 1,
b: 2,
c: 3
};
const object2 = Object.assign({}, object1);
console.log(object2.c);
// expected output: 3
Copy after login

Or use

obj=JSON.parse(JSON.stringify(this.templateData)); //this.templateData是父组件传递的对象
Copy after login

Applicability

When an abstract model has two aspects, one of which depends on the other. Encapsulating the two in independent objects allows them to be changed and reused independently

When one object changes, other objects need to be changed at the same time, but we don’t know how many objects need to be changed.

When an object must notify other objects, but it does not know who the specific object is. In other words, you don't want these objects to be tightly coupled.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to get your own properties by clicking in vue.js2.0

In vue.js How to use modifier .self?

Explain in detail how to use this.$emit in vue.js

How to implement the password display and hide switching function in vue

How to use parent component to call child component events in Vue

Use $http to implement asynchronous uploading of Excel files in angularjs

The above is the detailed content of How to treat deep copy in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!