首页 / VUE / vue之vue-router
vue之vue-router
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了vue之vue-router,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1376字,纯文字阅读大概需要2分钟。
内容图文
![vue之vue-router](/upload/InfoBanner/zyjiaocheng/997/18d4c9ae4537414194f0268b4ca39d96.jpg)
vue知识点汇总
vue-router(路由)
1.懒加载方式:const routers = [{
path:’/index’,
component:(resolve) => require([’’],resolve)
}]
2.html5的history路由模式
const routerConfig = {
mode:‘history’,
routes:routers
}
3.路由path加参数
const routers = [{
path:’/user/:id’,
component:(resolve) => require([’’],resolve)
}]
访问路径:localhost:8080/user/1234
拿到id:this.$route.params.id
4.路由跳转
1.点击
tag:渲染的标签 replace:不会留下history记录,返回键返回不到当前页面
2.
命名的路由
this.$router.push({name:'user',params:{paicheNo: obj.paicheNo}})
取数据:this.$route.params.paicheNo
带查询参数的路由,变成:regist/paicheNo=obj.paicheNo
this.$router.push({path:'regist',query:{paicheNo: obj.paicheNo}})
取数据:this.$route.query.paicheNo
this.$router.replace('/user/123') 不会像history里添加数据,点击返回会跳转到上上页
this.$router.go(-1) 返回上一页 this.$router.go(2) 前进两页
5.vue-router 导航钩子函数
beforeEach和afterEach
router.beforeEach((to,from,next) => {
})
to:即将要进入目标的路由对象
from:当前导航即将要离开的路由对象
next:调用该方法进入下一个钩子
6.嵌套路由 (选项卡)
{
path: ‘/’,
// component: Home,
component: resolve => require([’@/components/Home.vue’], resolve),
meta: {
requiresAuth: true
},
children: [{
path: ‘/’,
name: ‘index’,
// component: index,
component: resolve => require([’@/components/index.vue’], resolve),
meta: {
requiresAuth: true
}
}]
}
内容总结
以上是互联网集市为您收集整理的vue之vue-router全部内容,希望文章能够帮你解决vue之vue-router所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。