为什么emitter.on,emitter.off冒红报错呢?
来源:5-10 ValidateForm 编码第三部分 - 寻找外援 mitt
顾先生r
2023-01-13
安装mitt成功了的
<script lang='ts'>
import { defineComponent, onUnmounted } from 'vue'
import mitt from 'mitt'
const emitter = mitt()
export default defineComponent({
emits:['submit'],
setup(props,context){
const onSubmit = () => {
context.emit('submit',true)
}
const callback = (test:string) => {
console.log(test)
}
emitter.on('form-item-create', callback)
onUnmounted(()=>{
emitter.off('form-item-create', callback)
})
return {
onSubmit
}
}
})
</script>
写回答
1回答
-
张轩
2023-01-14
同学你好
请看下一小节,关于新版 mitt 的一些定义更新:
https://coding.imooc.com/lesson/449.html#mid=46661
00
相似问题