码迷,mamicode.com
首页 > 其他好文 > 详细

vue路由

时间:2019-10-11 20:30:50      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:lang   routes   路由   pat   script   detail   out   ted   temp   

路由跳转

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路由

标签:lang   routes   路由   pat   script   detail   out   ted   temp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!