Vue.set(vm.someObject, 'propertyName', value)
// Or using alias
this.$set(this.someObject, 'propertyName', value)
// For an array, simply repalce propertyName with the index
this.$set(this.someArray, indexOfItem, value)
// Or assign new props to an object
this.someObject = Object.assign({}, this.someObject, { a: 1, b: 2 })
VUE 2 >>>
data() {
return {
personObject: {
name: 'John Doe'
}
}
},
methods: {
addBio(bio) {
this.$set(this.personObject, 'bio', bio) // this was needed on vue 2
}
VUE 3 >>>
methods: {
addBio(bio) {
this.personObject['bio'] = bio // no more this.$set in vue 3
}
}