You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 组件内路由钩子// 进入之前,用于数据获取beforeRouteEnter(to,from,next){// 此时得不到组件实例thisnext(vm=>{// 自动得到进入路由后的组件实例vm// 此时可以得到组件实例vmconsole.log(vm)})}// 路由跳转时,组件不变,路由参数改变时触发// 用于数据获取,推荐beforeRouteUpdate(to,from,next){// 若触发update,表示缓存了组件,不会再触发beforeRouteEnter,mountednext()}// 路由离开时// 用于修改表单后未保存,离开之前提醒是否离开beforeRouteLeave(to,from,next){// next()if(global.confirm('are you sure?')){// 确定后才会离开next()}}// 触发顺序// beforeEach// app beforeEnter// todo beforeEnter// before resolve// after each
异步加载组件,提高首屏加载速度
routes.js
// 路由配置钩子// routes.js 路由映射关系文件// 异步加载组件需要安装 npm i babel-plugin-syntax-dynamic-import// .babelrc 配置 "plugins":["syntax-dynamic-import"]// import Todo from '../views/todo/todo.vue'importLoginfrom'../views/login/login.vue'exportdefault[{path: '/',redirect: '/app',// 跳转到 path '/app'},{path: '/app/:id',// 只能匹配地址 /app/xxx// props: true, // 会将path 的id当作props传入组件Todo,组件内直接this.id取得// component: Todo,component: ()=>import('../views/todo/todo.vue'),// 需要时才会加载该组件,异步加载name: 'todo',beforeEnter(to,from,next){// 每次进入路由前触发// 在before each 和 before resolve 中间触发next()// 不执行next则不会进入路由},},{path: '/login',props: {// 也可以自定义 propsid: '456',},component: Login,name: 'login'},]
Vue-router
Vue-router 路由参数传递
The text was updated successfully, but these errors were encountered: