此.$emit在';安装';vue.js组件的方法
此.$emit在';安装';vue.js组件的方法,vue.js,Vue.js,this.$emit在mountedhook中不起作用。如何处理? 我必须添加setTimeout,但这不是个好主意 mounted() { this.input = $(this.$el).find('.after-input'); if(this.propEmitChangedOnMount && !this.isDisabled) { this.$nextTick(() => { console.log(this.propName); co
this.$emit
在mounted
hook中不起作用。如何处理?
我必须添加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);
}
}
},
添加.bind(此)
事件只能发出一个值。如果您使用的是vue devtools:您可以看到是否触发了事件。不,有很多值。此.$emit在其他方法中工作。或者在这种情况下使用setTimeout。尝试使用
this.$emit('changed',{prop:this.propName,value:this.value})代码>我在任何地方都找不到它,但我相信事件不能发出那样的多个值。它们可以。哦,所以它用它制作了一个数组。因此,如果您添加一个setTimeout()
,它会触发事件,但不会触发其他事件?
setTimeout(() => {
this.$emit('changed', this.propName, this.value);
}, 1900).bind(this)