【发布时间】:2020-07-16 19:07:37
【问题描述】:
我似乎难以跟踪组件内计算对象的深层变化。
我有一个计算的计划对象定义为:
computed: {
schedule() { // return the current schedule object
return this.$store.getters['schedules/getScheduleByName'](this.picked)
}
},
我定义了一块手表:
watch: {
schedule: {
handler() {
this.activeColor = 'blue' // this is stored in the data function
},
deep: true,
},
},
这确实会跟踪变化。但是,因为调度程序对象似乎会随着组件加载而发生变化,所以颜色变化会立即发生,而不是在我手动更改对象属性之后发生。有谁知道如何实现颜色最初为红色然后在组件完全初始化后更改的效果?
提前谢谢你,
马丁
【问题讨论】:
-
为什么不把它放在一个方法中,在mounted() 挂钩中调用?
-
谢谢,你的意思是设置挂载钩子的颜色吗?我试图这样做,但它仍然被覆盖并且颜色是蓝色的。
标签: vue.js