this.$emit
在mounted
挂钩中不起作用。怎么处理呢?
我必须添加setTimeout
,但这不是一个好主意。
mounted() {
this.input = $(this.$el).find('.after-input');
if(this.propEmitChangedOnMount && !this.isDisabled) {
this.$nextTick(() => {
console.log(this.propName); console.log(this.value);
setTimeout(() => {
this.$emit('changed', this.propName, this.value);
}, 1900); // i have to add timeout to trigger change on mount
});
}
},
在watcher
内,它运作正常。
watch: {
propInitialValue: function(val, oldVal) {
this.value = this.getValue(val);
},
value: function(val, oldVal) {
if( ! this.isDisabled ) {
this.$emit('changed', this.propName, val);
}
}
},
答案 0 :(得分:0)
添加.bind(this)
setTimeout(() => {
this.$emit('changed', this.propName, this.value);
}, 1900).bind(this)