参考:https://cn.vuejs.org/v2/guide/list.htmlhttps://cn.vuejs.org/v2/guide/reactivity.html
对于已经创建的实例,Vue 不能动态添加根级别的响应式属性。但是,可以使用 Vue.set(object, key, value) 方法向嵌套对象添加响应式属性。例如,对于:
var vm = new Vue({
data: {
userProfile: {
name: 'Anika'
}
}
})
你可以添加一个新的 age 属性到嵌套的 userProfile 对象:
Vue.set(vm.userProfile, 'age', 27)
你还可以使用 vm.$set 实例方法,它只是全局 Vue.set 的别名:
this.$set(this.userProfile, 'age', 27)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。