You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
542 B
21 lines
542 B
2 years ago
|
/**
|
||
|
* 实现一个继承的 数组类 代理掉 vue-router 生命钩子的数据
|
||
|
*/
|
||
|
class MyArray extends Array {
|
||
|
constructor(Router, vueOldHooks, hookFun) {
|
||
|
super();
|
||
|
this.Router = Router;
|
||
|
this.vueOldHooks = vueOldHooks;
|
||
|
this.hookFun = hookFun;
|
||
|
}
|
||
|
|
||
|
push(v) {
|
||
|
this.vueOldHooks.splice(0, 1, v);// 把vue-router路由生命钩子保存起来
|
||
|
this[this.length] = (to, from, next) => {
|
||
|
this.hookFun(to, from, next, this.Router);
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default MyArray;
|