vue中央事件总线bus

📅 2026/7/28 19:58:09 👁️ 阅读次数 📝 编程学习
vue中央事件总线bus

全局

1、新建 eventBus.js 文件

import Vue from 'vue' export default new Vue()

2、引用 (哪里要用就import eventBus.js 文件)

$on : 监听
$emit :触发
$off : 释放 ( 监听后一定要在beforeDestroy中释放)