尝试使用vue手表方法,但即使使用deep:true
,它似乎也不会触发某些对象。Vue手表不触发
在我的组件中,我收到一个数组作为道具,这些字段是用于创建以下形式的字段 。 我可以构建形式和动态地将它们绑定到名为crudModelCreate
对象,一切工作正常(我在VUE开发工具看,甚至submiting形式按计划工作)
但我想关注这些变化的一个问题在那个动态的对象中。
<md-input v-for="(field, rowIndex) in fields" :key="field.id" v-model="crudModelCreate[field.name]" maxlength="250"></md-input>
...
data() {
return {
state: 1, // This gets changed somewhere in the middle and changes fine
crudModelCreate: {},
}
},
...
watch: {
'state': {
handler: function(val, oldVal) {
this.$emit("changedState", this.state);
// this works fine
},
},
'crudModelCreate': {
handler: function(val, oldVal) {
console.log("beep1")
this.$emit("updatedCreate", this.crudModelCreate);
// This doesn't work
},
deep: true,
immediate: true
},
}
如何在你的对象的变化进行? –
您可能必须使用['Vue.set'](https://vuejs.org/v2/api/#Vue-set)来更新对象属性,尤其是在添加新属性时。 –
[Vue.js观看深层属性]的可能重复(https://stackoverflow.com/questions/44760474/vue-js-watching-deep-properties) –