标签:ons dex llb params 监听 模式 export pre default
1 const eventList = {} 2 //发布 3 const $on = function(eventName,callback){ 4 if(!eventList[eventName]){ 5 eventList[eventName] = []; 6 } 7 8 eventList[eventName].push(callback); 9 } 10 //监听 11 const $emit = function(eventName,params){ 12 if(eventList[eventName]){ 13 var arr = eventList[eventName]; 14 arr.forEach((cb)=>{ 15 cb(params) 16 }) 17 } 18 } 19 //解绑 20 const $off = function(eventName,callback){ 21 if(eventList[eventName]){ 22 if(callback){ 23 var index = eventList[eventName].indexOf(callback); 24 eventList[eventName].splice(index,1); 25 }else{ 26 eventList[eventName].length = 0; 27 } 28 } 29 } 30 31 32 export default { 33 $on, 34 $emit, 35 $off 36 }
标签:ons dex llb params 监听 模式 export pre default
原文地址:https://www.cnblogs.com/learninginto/p/12962046.html