2021年4月12日 星期一

Electron + Vue3 裡面 mitt 用法

紀錄一下 在Electron + Vue3 裡面使用 mitt的方法

1.安裝指令
 npm install --save mitt

2.在main.js裡面做新增修改
新增:
import mitt from "mitt";
const emitter = mitt()

修改:

const app = createApp(App,Antd).use(Antd)
app.config.globalProperties.emitter = emitter
app.mount('#app')


3.可使用以下指令

this.emitter.on << 設立監聽等別人來呼叫

this.emitter.on("maingetclick", () => {
    this.mainmsg +=1;
})



this.emitter.emit << 呼叫

this.emitter.emit('maingetclick');



this.emitter.off << 關閉


沒有留言:

張貼留言