java router_vue-router

本文详细介绍了Vue Router的history模式,如何创建SPA,以及动态路由的使用。通过this.$router.push实现路由跳转,并讲解了命名路由、嵌套路由和参数传递。同时提到了多视图加载的概念,展示了如何在实际应用中配置和使用。
摘要由CSDN通过智能技术生成

vue router

vue-router 就是封装 浏览器中history。

使用vue-router用来构建SPA

或者 this.$router.push({path: '/'}) 相当于

主键的渲染

动态路由

模式

匹配路径

$router.params

/usr/:username

/usr/xx

{ username: 'xx'}

hash & history

hash 默认模式,路由中展现为 url/#/, 后面的url取hash

history : mode 设置为history 后,就和平时使用的url一样

export default new Router({

mode: 'history',

routers : [{

path: '/',

name: main,

component:Main

}

]

})

嵌套路由

export default new Router({

mode: 'history',

routers : [{

path: '/',

name: main,

component:Main,

children: [

{

path: 'title',

name: title,

component:Title,

}

]

}

]

})

在Main组件中也要加

编程路由

this.$router.push('name')

this.$router.push({path:'name'})

this.$router.push({path:'name?id=123'})

this.$router.push({path:'name', query: {a: 123}})

命名路由

使用name 进行 路由跳转, v-bind:to='{name: 'xx'}', xx为路由定义的name值

命名视图

加载多个视图, 一般用不到

export default new Router({

mode: 'history',

routers : [{

path: '/',

name: main,

component: {

default: List,

title: Title,

img: Img

}

}

]

})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值