I am trying to understand the different ways to add a reactive property. I know that I can't add a property directly to the root level so I have a user object set in my data:
data() {
return {
user: {
}
}
}
from here though is where I get confused because the docs say that using Vue.set is the way to add a new reactive property to the object, so in this example:
Vue.set(this.user, 'first_name', 'Bob')
However, I tried a different approach and made a button that triggered a method and inside of it, did the following:
testFunc() {
let names = ["Bob", "Vin", "Mark"]
this.user.test_property = names[Math.floor(Math.random() * names.length];
}
and this worked..I tested in the Vue Dev tools and saw the property test_property added to the object and changes to it each time the button was clicked. Why would this work if Vue.set() is the only way to make a new reactive property?
Lastly, I noticed that if I did the following <input v-model="user.other_new_property" />, this tracks changes as well on new properties....not sure why this works either.vue