想要在v-my-directive
的bind触发时,绑定对组件my-input
的someEvent事件监听
<template>
<my-input v-my-directive="xxx"></my-input>
</template>
inside MyInput file:
<template>
<div class="my-input">
<input type="text"/>
</div>
</template>
<script>
export default {
name: 'MyInput',
created() {
this.trigger()
},
methods: {
trigger(){
this.$emit('someEvent')
}
}
}
</script>
inside MyDirective file:
export default Vue.directive('my-directive', {
bind(el, binding, vnode) {
// listen to someEvent here
}
})
是否有办法做到?
指令中使用 vnode.componentInstance.$on()