watch: {
value: function (val, oldVal) {
if (val) {
this.form = val;
this.$refs.editor.setEditorContent(val.exercisesContent);
this.options = val.options;
// this.setExercises(val);
}
},
formData: {
handler: function (val) {
console.log(val, 'watch');
if (val) {
this.setExercises(val);
}
},
},
}
观察属性 第一次赋值的时候并不会被调用 用来做初始化的时候是不行的
mounted() {
this.$nextTick(() => {
if (this.formData && this.formData.exercisesContent) {
this.setExercises(this.formData);
}
})
},
mounted 不一定保证所有的组件被挂载 比如在子组件中new E()
在mounted中调用子组件.e.xxx就可能报错