为什么vue监听到对象数据,但是对象内的值取不到?-灵析社区

无心插柳柳成萌

父组件: /* 查询所有的数据字典 */ async getAllDict(){ this.animalTypeData = await this.getDictionaryByCode("AnimalType"); this.$set(this.allDict, "AnimalType", this.animalTypeData); }, 子组件watch: /* 数据字典 */ allDict: { handler(allDict) { console.log(allDict); console.log(allDict.AnimalType); Object.keys(allDict).forEach(key => console.log(key, allDict[key])); this.animalTypeData = allDict.AnimalType; }, deep: true,// 是否开启深度监听 immediate: true// 是否初始化时就执行一次 }, 上面用这种this.$set(this.allDict, "AnimalType", this.animalTypeData);赋值方式试了没问题,后面没采用watch的方式去监听allDict,直接用了计算属性也能拿到 // 类型数据 computed: { animalTypeData() { return this.allDict.AnimalType; } }

阅读量:1

点赞量:0

问AI