国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

vue路由跳轉(zhuǎn)傳遞參數(shù)的方式總結(jié)

瀏覽:38日期:2023-01-22 08:24:11

日常業(yè)務(wù)中,路由跳轉(zhuǎn)的同時傳遞參數(shù)是比較常見的,傳參的方式有三種:

1)通過動態(tài)路由方式

//路由配置文件中 配置動態(tài)路由{ path: ’/detail/:id’, name: ’Detail’, component: Detail }//跳轉(zhuǎn)時頁面var id = 1;this.$router.push(’/detail/’ + id) //跳轉(zhuǎn)后頁面獲取參數(shù)this.$route.params.id

2)通過query屬性傳值

//路由配置文件中{ path: ’/detail’, name: ’Detail’, component: Detail }//跳轉(zhuǎn)時頁面this.$router.push({ path: ’/detail’, query: { name: ’張三’, id: 1, }}) //跳轉(zhuǎn)后頁面獲取參數(shù)對象this.$route.query

3)通過params屬性傳值

//路由配置文件中{ path: ’/detail’, name: ’Detail’, component: Detail }//跳轉(zhuǎn)時頁面this.$router.push({ name: ’Detail’, params: { name: ’張三’, id: 1, }}) //跳轉(zhuǎn)后頁面獲取參數(shù)對象this.$route.params

總結(jié):

1.動態(tài)路由和query屬性傳值 頁面刷新參數(shù)不會丟失, params會丟失

2.動態(tài)路由一般用來傳一個參數(shù)時居多(如詳情頁的id), query、params可以傳遞一個也可以傳遞多個參數(shù) 。

補(bǔ)充方法:

頁面刷新數(shù)據(jù)不會丟失

methods:{ insurance(id) { //直接調(diào)用$router.push 實(shí)現(xiàn)攜帶參數(shù)的跳轉(zhuǎn) this.$router.push({ path: `/particulars/${id}`, })}

需要對應(yīng)路由配置如下:

this.$route.params.id

到此這篇關(guān)于vue路由跳轉(zhuǎn)傳遞參數(shù)的方式總結(jié)的文章就介紹到這了,更多相關(guān)vue路由跳轉(zhuǎn)傳遞參數(shù)的三種方式內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 二连浩特市| 博客| 镇宁| 会泽县| 台前县| 翼城县| 西充县| 黄大仙区| 忻州市| 昭苏县| 凤翔县| 盘锦市| 崇阳县| 普兰县| 鹤岗市| 洛宁县| 江源县| 通许县| 河池市| 正定县| 云林县| 砀山县| 南昌市| 靖安县| 静乐县| 探索| 大方县| 嘉祥县| 任丘市| 石阡县| 明星| 白城市| 铜鼓县| 锦屏县| 个旧市| 普定县| 普宁市| 桃园县| 工布江达县| 龙井市| 即墨市|