extend.js
export const eventBus = new Vue();
上一页
import { eventBus } from "../common/extend.js";
created() {
this.registerEvent();
},
methods: {
registerEvent(){
eventBus.$on('isRead',(data) => {
console.log('eventBus---data===',data);
if(data){
this.handleSubmit();
}
})
},
}
下一页
import { eventBus } from "../common/extend.js";
methods: {
agree() {
eventBus.$emit('isRead', true)
this.$router.go(-1);
},
},
在uniapp里
上一页
uni.$on('isRead', this.handleSubmit);
下一页
agree() {
uni.$emit('isRead', true);
uni.navigateBack();
}
文章展示了如何在uniapp中使用自定义事件总线(eventBus)进行组件间通信,上一页组件注册监听isRead事件并处理数据,下一页组件触发事件并传递状态,实现页面间的交互,如阅读确认功能。
708

被折叠的 条评论
为什么被折叠?



