首页 > 其他 > 详细

vue路由

时间:2019-10-11 19:53:55      阅读:74      评论:0      收藏:0      [点我收藏+]

路由跳转

this.$router.push(‘/course‘);
this.$router.push({name: course});
this.$router.go(-1);
this.$router.go(1);
<router-link to="/course">课程页</router-link>
<router-link :to="{name: ‘course‘}">课程页</router-link>

路由传参

第一种

router.js
routes: [
	// ...
    {
        path: ‘/course/:id/detail‘,
        name: ‘course-detail‘,
        component: CourseDetail
    },
]
跳转.vue
<template>
	<!-- 标签跳转 -->
	<router-link :to="`/course/${course.id}/detail`">{{ course.name }}</router-link>
</template>
<script>
	// ...
    goDetail() {
        // 逻辑跳转
        this.$router.push(`/course/${this.course.id}/detail`);
    }
</script>
接收.vue
created() {
    let id = this.$route.params.id;
}

第二种

router.js
routes: [
	// ...
    {
        path: ‘/course/detail‘,
        name: ‘course-detail‘,
        component: CourseDetail
    },
]
跳转.vue
<template>
	<!-- 标签跳转 -->
	<router-link :to="{
            name: ‘course-detail‘,
            query: {id: course.id}
        }">{{ course.name }}</router-link>
</template>
<script>
	// ...
    goDetail() {
        // 逻辑跳转
        this.$router.push({
            name: ‘course-detail‘,
            query: {
                id: this.course.id
            }
        });
    }
</script>
接收.vue
created() {
    let id = this.$route.query.id;
}

vue路由

原文:https://www.cnblogs.com/Sunbreaker/p/11656133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!