UNPKG

@bye_past/vue-keep

Version:

缓存你的页面组件, 使得可以比手机APP更好的体验效果

22 lines (21 loc) 417 B
export function useCallbacks() { let handlers = []; function add(name, handler) { const obj = typeof name === 'function' ? name : { name, handler }; handlers.push(obj); return () => { const i = handlers.indexOf(obj); if (i > -1) { handlers.splice(i, 1); } }; } function reset() { handlers = []; } return { add, list: () => handlers, reset, }; }