How to create a new object in VueJS?

Vue.component('list_appointments', {
 delimiters: ['{>', '<}'],
 template: '#list_appointments-template',
 data: function () {
 return {
 active_list_appointments_template: false,
 drug: {
 id: null,
 patient: null,
 disease_history: null,
 drug: null,
 start_day: null,
 end_day: null,
 is_delete: false,
},
 list_appointments_drugs: [],
}
},
 methods: {
 addDrug: function () {
 // want to add to list_appointments_drugs a new object drug, but it turns out that the added model
this.list_appointments_drugs.unshift(this.drug)
},
 editDrug: function () {

},
 deleteDrug: function () {

},
 openTemplate: function () {
 this.active_list_appointments_template = true
},
 closeTemplate: function () {
 this.active_list_appointments_template = false
},
 onCancel: function () {
this.close()
},
 onConfirm: function () {
this.close()
}
},
 beforeCreate: function () {
 var self = this
 //Patient profiles
 axios.get('http://' + window.location.host + '/api/patients/' + document.getElementById('id_patient').innerText + '/?format=json').then(function (response) {
 self.patient = response.data
 }).catch(function (error) {
console.log(error);
});
 //Current history
 axios.get('http://' + window.location.host + '/api/disease_stories/' + document.getElementById('id_disease_history').innerText + '/?format=json').then(function (response) {
 self.disease_history = response.data
 }).catch(function (error) {
console.log(error);
});
}
})
June 5th 19 at 21:30
1 answer
June 5th 19 at 21:32
Solution
this.list_appointments_drugs.unshift({ ...this.drug })

Find more questions by tags JavaScriptVue.js