vue关于router路由的详细使用

欢迎来到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应用在场景中的案例

 

未完待续....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

快乐的逗号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值