VUE-UNI事件转发监听

VUE以及uni-app 如果在项目中事件转发以及监听事件

在业务页面 a.vue 里面,调用了一个第三方接口,这个接口的回调是在项目的app.vue 的 onShow 里面给的回调,那我现在在a.vue 里面怎么处理。这个时候就需要做事件的转发,在a 页面做事件的监听

方法:

store下边新建一个js eventBus.js

import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;

app.vue里面作引用

import EventBus from './store/eventBus.js';

onShow: function(options) {
        
       EventBus.$emit('onAppShown', parmers);   
        
},

在a.vue页面中

import EventBus from '../../../store/eventBus.js';

beforeDestroy(){
            EventBus.$off('onAppShown', this.checkPayResult);
        },
 mounted() {
            EventBus.$on('onAppShown', this.checkPayResult);
},
methods: {
            checkPayResult(param){
                console.log("到这里了")
                console.log(param)
              
            },
}

 

posted @ 2024-12-05 13:00  haonanElva  阅读(39)  评论(0)    收藏  举报