美文网首页uni-appuni-app交流圈Uni-app
uni-app仿h5+fire自定义事件触发监听

uni-app仿h5+fire自定义事件触发监听

作者: 路够黑光才亮 | 来源:发表于2019-04-26 17:40 被阅读1次

    仿h5+fire自定义事件触发监听


    uni-app调用

    event.js

    源码记录

    1.js下载地址   
    
        [event.js](https://ext.dcloud.net.cn/plugin?id=333)     
    
        [源码记录](https://blog.csdn.net/qq_30849965/article/details/89603661)
    
    2.js文件直接拖入
    
    3.import event from 'common/event.js'
    
    4.Vue.prototype.event = event;
    

    接下来就可以使用了

    使用实例

    1.事件监听

    
    //事件监听
    
    //params:page:页面的地址(确报每个页面唯一)
    
    //      type: 事件类型
    
    //      callback: 回调参数
    
    this.event.on('index/index','test',function(args){
    
          console.log('testindex:' + args);
    
    });
    
    //结果:testindex:index
    
    

    2.事件触发

    
    //事件触发
    
    //params:obj:{type:'test',page:'index/index'}
    
    //            type:事件类型,对应监听中的type,必须
    
    //            page: 默认all,表示所有页面, 对应监听中的page ,非必须
    
    //          后面的参数对应callback中参数
    
    this.event.trigger({type:'test',page:'index/index'},'index');
    
    

    目前使用没有问题,不保证有没有bug,毕竟小菜鸟,希望各位大佬借鉴并提出问题

    感谢有位老哥提点,提出问题,==目前已修改==

    相关文章

      网友评论

        本文标题:uni-app仿h5+fire自定义事件触发监听

        本文链接:https://www.haomeiwen.com/subject/qqmqnqtx.html