Vue基础笔记4

路由传参

第一种

router.js

{
    path: '/course/detail/:pk/',
    name: 'course-detail',
    component: CourseDetail
}

传递层

<!-- card的内容
{
	id: 1,
	bgColor: 'red',
	title: 'Python基础'
}
-->
<router-link :to="`/course/detail/${card.id}`">详情页</router-link>

接收层

let id = this.$route.params.pk

演变体

"""
{
    path: '/course/:pk/:name/detail',
    name: 'course-detail',
    component: CourseDetail
}

<router-link :to="`/course/${card.id}/${card.title}/detail`">详情页</router-link>

let id = this.$route.params.pk
let title = this.$route.params.name
"""

第二种

router.js

{
    // 浏览器链接显示:/course/detail,注:课程id是通过数据包方式传递
    path: '/course/detail',
    name: 'course-detail',
    component: CourseDetail
}

传递层

<!-- card的内容
{
	id: 1,
	bgColor: 'red',
	title: 'Python基础'
}
-->
<router-link :to="{
                  name: 'course-detail',
                  params: {pk: card.id}
                  }">详情页</router-link>

接收层

let id = this.$route.params.pk

第三种

router.js

{
    // 浏览器链接显示:/course/detail?pk=1,注:课程id是通过路由拼接方式传递
    path: '/course/detail',
    name: 'course-detail',
    component: CourseDetail
}

传递层

<!-- card的内容
{
	id: 1,
	bgColor: 'red',
	title: 'Python基础'
}
-->
<router-link :to="{
                  name: 'course-detail',
                  query: {pk: card.id}
                  }">详情页</router-link>

接收层

let id = this.$route.query.pk
posted @ 2019-09-02 08:19  Hello_Jack  阅读(112)  评论(0编辑  收藏  举报
# 页脚html代码 /*头部导航栏*/ #navigator { font-size:15px; border-bottom: 1px solid #ededed; border-top: 1px solid #ededed; height: 60px;/*导航栏高度,原始50*/ clear: both; margin-top: 25px; } /*导航栏设置,可以自定义导航栏的目录*/ #navList { min-height: 35px; float: left; } #navList li { /*每一个栏目节点*/ float: left; margin: 0 5px 0 0; /*这里原来是0 40px 0 0 */ } #navList a { /*栏目文字的格式*/ display: block; width: 5em; height: 22px; float: left; text-align: center; padding-top: 19px; }