Reputation: 97
I am looking for a way to replace the object under data.
data() {
return {
form:{ .... }
}
}
I have learnt that I cannot directly change data itself so I moved all my variables under form
. I want to replace all the data inside the form
so that my form values are changed.
I have found a way to update single values like this;
this.$set(this.someObject, 'planes', true)
where the solution is here but I want to replace all the form object.
update_form(){
let self = this
$.ajax({
url: '/formdata/',
type: 'GET',
success: function(response){
self.$set(self.form, needToUpdateAll)
}
});
},
I am stuck right where it says needToUpdateAll
. From the docs, it says target, key, value
.
I am looking for a solution because I do not want to assign all values one by one (well the object has nested and nested objects :()
Any walk-around would be appreciated
Upvotes: 0
Views: 73
Reputation: 29020
This is not complicated. You don't need $set. Is update_form()
in methods
? If so, just do this.form = response
. Top level names in your data
are directly available in the rest of your Vue object.
Upvotes: 3