A
A
Alex Phil2018-02-14 17:55:40
JavaScript
Alex Phil, 2018-02-14 17:55:40

How to create a copy of an object from data in vuejs?

The question arose of creating a copy of the object / array from the data of the vue instance. When I do something like this:

let filterDate = {};
filterDate = this.filters.dates;

nothing comes out and when changing the supposedly new object, reactive binding continues to work. Please tell me how to get around this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kn1ght_t, 2018-02-14
@Flex99

const copyObject = JSON.parse(JSON.stringify(object))

or
const copyObject = Object.assign({}, object);

A
Alexander Aksentiev, 2018-02-14
@Sanasol

https://lodash.com/docs/4.17.4#clone
https://lodash.com/docs/4.17.4#cloneDeep

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question