I am pulling data from an API, suppose the response looks like this
users: [{id: 1, name: 'Daft Punk'}, ...]
and I assign it to the vm by:
this.users = users;
Now, I show these users in a list and would like to toggle some state on a specific user, such as "visible" or "enabled" etc.
Currently I do this:
methods: {
enableUser: function (user) {
if (user.enabled === undefined) {
Vue.set(user, 'enabled', false);
}
user.enabled= !user.enabled;
}
}
I do the
if (user.enabled === undefined) {
Vue.set(user, 'enabled', false);
}
part since the enabled property is not present in the response object from the API and I want to be able to use that property for v-show and similar things.
Is there a better way of assigning properties that should be reactive? Doesn't feel right writing that snippet for every custom property that I want to use..