欢迎来到QQ技术交流群:126095418
1、 vue-router的基本应用
export default new Router({
routers: [
{
name: 'home',
path: '/',
component: Home
},
{
name: 'info',
path: '/info/:id',
component: Info
}
]
})
2、 router的各种用法介绍
2.1、在页面结构上的用法
<router-view :to="{path: '/'}"></router-view>
<router-view :to="{path: '/info', params: {id: 1}}"></router-view>
<router-view :to="{name: 'home'}"></router-view>
<router-view :to="{name: 'info', params: {id: 1}}"></router-view>
2.2、在js中的用法
this.$router.path('/');
this.$router.path({path: '/'});
this.$router.path('/info/1');
this.$router.path({path: '/info/1'});
this.$router.push({name: 'home'});
this.$router.push({name: 'home', params: {id:1}});
2.3、带有参数的路由跳转
this.$router.push('/?name=张三&sex=男&age=18');
this.$router.push({path: '/', query: {name: '张三', sex: '男', age: '18'}});
this.$router.push({name: 'home', query: {name: '张三', sex: '男', age: '18'}});
3、 router应用在场景中的案例
未完待续....