[1118 | Day61] Vue-CLI routing of mass participation in the project

A label parameter passing mode:

The first

router.js
{
    path: '/course/detail/:pk',
    name: 'course-detail',
    component: CourseDetail
}
Transport layer
<!-- card的内容
{
    id: 1,
    bgColor: 'red',
    title: 'Python基础'
}
-->
<router-link :to="`/course/detail/${card.id}`">详情页</router-link>
Receiving layer
let id = this.$route.params.pk
Evolution body
"""
{
    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
"""

The second

router.js
{
    // 浏览器链接显示:/course/detail,注:课程id是通过数据包方式传递
    path: '/course/detail',
    name: 'course-detail',
    component: CourseDetail
}
Transport layer
<!-- card的内容
{
    id: 1,
    bgColor: 'red',
    title: 'Python基础'
}
-->
<router-link :to="{
                  name: 'course-detail',
                  params: {pk: card.id}
                  }">详情页</router-link>
Receiving layer
let id = this.$route.params.pk

The third

router.js
{
    // 浏览器链接显示:/course/detail?pk=1,注:课程id是通过路由拼接方式传递
    path: '/course/detail',
    name: 'course-detail',
    component: CourseDetail
}
Transport layer
<!-- card的内容
{
    id: 1,
    bgColor: 'red',
    title: 'Python基础'
}
-->
<router-link :to="{
                  name: 'course-detail',
                  query: {pk: card.id}
                  }">详情页</router-link>
Receiving layer
let id = this.$route.query.pk

Second pass logic parameters:. This $ router

The first

"""
路由:
path: '/course/detail/:pk'

跳转:id是存放课程id的变量
this.$router.push(`/course/detail/${id}`)

接收:
let id = this.$route.params.pk
"""

The second

"""
路由:
path: '/course/detail'

跳转:id是存放课程id的变量
this.$router.push({
                    'name': 'course-detail',
                    params: {pk: id}
                });

接收:
let id = this.$route.params.pk
"""

The third

"""
路由:
path: '/course/detail'

跳转:id是存放课程id的变量
this.$router.push({
                    'name': 'course-detail',
                    query: {pk: id}
                });

接收:
let id = this.$route.query.pk
"""

Guess you like

Origin www.cnblogs.com/fxyadela/p/11885774.html