国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

Vue-CLI項(xiàng)目中路由傳參的方式詳解

2024-05-06 15:35:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一.標(biāo)簽傳參方式:<router-link></router-link>

第一種

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

傳遞層

<!-- card的內(nèi)容{  id: 1,  bgColor: 'red',  title: 'Python基礎(chǔ)'}--><router-link :to="`/course/detail/${card.id}`">詳情頁(yè)</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`">詳情頁(yè)</router-link>let id = this.$route.params.pklet title = this.$route.params.name"""

第二種

router.js{  // 瀏覽器鏈接顯示:/course/detail,注:課程id是通過(guò)數(shù)據(jù)包方式傳遞  path: '/course/detail',  name: 'course-detail',  component: CourseDetail}

傳遞層

<!-- card的內(nèi)容{  id: 1,  bgColor: 'red',  title: 'Python基礎(chǔ)'}--><router-link :to="{         name: 'course-detail',         params: {pk: card.id}         }">詳情頁(yè)</router-link>

接收層

let id = this.$route.params.pk

第三種

router.js{  // 瀏覽器鏈接顯示:/course/detail?pk=1,注:課程id是通過(guò)路由拼接方式傳遞  path: '/course/detail',  name: 'course-detail',  component: CourseDetail}

傳遞層

<!-- card的內(nèi)容{  id: 1,  bgColor: 'red',  title: 'Python基礎(chǔ)'}--><router-link :to="{         name: 'course-detail',         query: {pk: card.id}         }">詳情頁(yè)</router-link>

接收層

let id = this.$route.query.pk

二.邏輯傳參:this.$router

第一種

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

跳轉(zhuǎn):id是存放課程id的變量

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

接收:

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

第二種

"""路由:path: '/course/detail'跳轉(zhuǎn):id是存放課程id的變量this.$router.push({          'name': 'course-detail',          params: {pk: id}        });接收:let id = this.$route.params.pk"""

第三種

"""路由:path: '/course/detail'跳轉(zhuǎn):id是存放課程id的變量this.$router.push({          'name': 'course-detail',          query: {pk: id}        });接收:let id = this.$route.query.pk"""

總結(jié)

以上所述是小編給大家介紹的Vue-CLI項(xiàng)目中路由傳參的方式詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 永泰县| 蚌埠市| 若羌县| 怀远县| 长春市| 兴隆县| 兰州市| 交口县| 察雅县| 读书| 广安市| 清徐县| 蓝山县| 高阳县| 梁山县| 兰州市| 石阡县| 吉隆县| 婺源县| 饶平县| 康马县| 望都县| 固原市| 平果县| 安阳市| 五峰| 万宁市| 丽水市| 汉中市| 斗六市| 宜宾市| 木兰县| 临沂市| 翁源县| 凤庆县| 乳山市| 深水埗区| 张家界市| 蒙城县| 共和县| 德昌县|