So I have the following code that either assigns or removes an existing 'role' to a user:
onAddRole(role) {
let roles = this.user.roles
roles.push(role)
this.$set(this.user, roles)
console.log(this.user.roles)
this.success.role_update = true
},
onRoleDelete(selected_role) {
let i = this.user.roles.map(role => role.id).indexOf(selected_role.id)
if (i !== -1) {
let roles = this.user.roles
roles.splice(i, 1)
this.$set(this.user, roles)
console.log(this.user.roles)
this.success.role_update = true
}
}
Here is my data property for the component:
data: function() {
return {
user: null,
success: {
permission: null,
invalidation: null,
fetch: null,
save: null,
role_update: null
},
loading: false
}
},
And here is a snippet of the relevant html:
<b-row>
<b-col md="6">
<b-row v-if="user">
<b-col md="12">
<user-roles
:user="user"
@add_role="onAddRole"
@set_role="onRoleSet"
@role_failure="roleFail"
@role_delete="onRoleDelete"
/>
</b-col>
</b-row>
<loading v-if="loading" />
</b-col>
</b-row>
Basically this code works fine if I add a role once or twice. However, after the third time I remove or add a user role, Vue stops re-rendering the component. Any ideas why this would happen?
The console.logs show that the property itself is updated correctly, but the view does not update.