myArray.js 542 B

1234567891011121314151617181920
  1. /**
  2. * 实现一个继承的 数组类 代理掉 vue-router 生命钩子的数据
  3. */
  4. class MyArray extends Array {
  5. constructor(Router, vueOldHooks, hookFun) {
  6. super();
  7. this.Router = Router;
  8. this.vueOldHooks = vueOldHooks;
  9. this.hookFun = hookFun;
  10. }
  11. push(v) {
  12. this.vueOldHooks.splice(0, 1, v);// 把vue-router路由生命钩子保存起来
  13. this[this.length] = (to, from, next) => {
  14. this.hookFun(to, from, next, this.Router);
  15. };
  16. }
  17. }
  18. export default MyArray;