1)引入 getCurrentInstance
import { ref, onMounted, onUnmounted, getCurrentInstance } from "vue";
var vueProxy = getCurrentInstance();
2)监听与销毁
onMounted(() => {
vueProxy.proxy.$mittBus.on('historyShowDetail', showDetail)
})
onUnmounted(() => {
vueProxy.proxy.$mittBus.off('historyShowDetail')
})
3)监听到后执行的方法
const showDetail = () => {
}
4)另一个页面发送
import { ref, getCurrentInstance } from 'vue'
var vueProxy = getCurrentInstance();
const showDetail = () => {
vueProxy.proxy.$mittBus.emit('historyShowDetail', {})
}