I'm currently developing a small application to register devices on a database.
For the frontend I decided to use VueJS.
This is how I am initializing the app:
//App Vuejs
var app = new Vue({
el: '#register-device-app',
data: {
currentDevice: {
internalid: '',
imei: '',
tel: ''
},
devices[]
},
....
});
I'm binding the internalid, imei, tel and some other fields to a form and the data is stored on app.currentDevice which is great.
Now I would like to push the app.currentDevice to the array devices[] so I can add more.
The problem I am facing is that if I use app.devices.push(app.currentDevice), as soon as I modify the content of the currentDevice, since the object in the array is the same, the data in the array will also change, which I don't want.
I want to have the devices array to be like a local mini-database that will only hold the information until I send it to the database.
The solution I found was to use jQuery extend() app.devices.push(jQuery.extend({}, app.currentDevice)); but I don't think this is the best solution and I'd like to know if there are some other easy and more elegant ways to do this.
Can someone leave a suggestion?
Thank you so much!