Ruttyj
Ruttyj

Reputation: 943

VueJS Passing object in props

I am building controllers for sets of items. I am currently create a Javascript object, complete with functions and storing it in the data of the Vue instance. I am then passing this object like: <dynamic-table :table-object="objTable"></dynamic-table>

I am wondering if this is passed by reference or is it making a deep copy of the object every time the view is rendered.

I know VueEx might be a better solution but I am not able to use NodeJS for this project.

Upvotes: 2

Views: 1015

Answers (1)

user4345609
user4345609

Reputation:

The object is passed by reference. You can make a deep copy of the object inside the <dynamic-table>-component as follows:

data() {
    return {
      tableObject: JSON.parse(JSON.stringify(this.tableObj)),
    };
},

Upvotes: 2

Related Questions