vue mysql交互_vue前后端交互

路由传参

标签传参方式:

传参方式

router.js

{

path: '/course/detail/:pk',

name: 'course-detail',

component: CourseDetail

}

传递层

详情页

接收层

let id = this.$route.params.pk

演变体

"""

{

path: '/course/:pk/:name/detail',

name: 'course-detail',

component: CourseDetail

}

详情页

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

}

传递层

详情页

接收层

let id = this.$route.params.pk

第三种

router.js

{

// 浏览器链接显示:/course/detail?pk=1,注:课程id是通过路由拼接方式传递

path: '/course/detail',

name: 'course-detail',

component: CourseDetail

}

传递层

详情页

接收层

let id = this.$route.query.pk

逻辑传参:this.$router

第一种

"""

路由:

path: '/course/detail/:pk'

跳转:id是存放课程id的变量

this.$router.push(`/course/detail/${id}`)

接收:

let id = this.$route.params.pk

"""

第二种

"""

路由:

path: '/course/detail'

跳转:id是存放课程id的变量

this.$router.push({

'name': 'course-detail',

params: {pk: id}

});

接收:

let id = this.$route.params.pk

"""

第三种

"""

路由:

path: '/course/detail'

跳转:id是存放课程id的变量

this.$router.push({

'name': 'course-detail',

query: {pk: id}

});

接收:

let id = this.$route.query.pk

"""

历史记录跳转

"""

返回历史记录上一页:

this.$router.go(-1)

去向历史记录下两页:

this.$router.go(-2)

"""

路由汇总大案例

router.js

import Vue from 'vue'

import Router from 'vue-router'

import Course from './views/Course'

import CourseDetail from './views/CourseDetail'

Vue.use(Router);

export default new Router({

mode: 'history',

base: process.env.BASE_URL,

routes: [

{

path: '/course',

name: 'course',

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值