Vue頁(yè)面跳轉(zhuǎn)傳遞參數(shù)及接收方式
最近接觸了vue項(xiàng)目,這里記錄一下vue跳轉(zhuǎn)到下一頁(yè)面攜帶參數(shù)的兩種方式。
典型應(yīng)用場(chǎng)景:列表頁(yè)跳轉(zhuǎn)到詳情頁(yè)
一、配置路由
文件路徑:src/router/config.php
import Vue from ’vue’import Router from ’vue-router’ import classify from ’.././components/classify/classify.vue’ import classifyChild from ’.././components/classify/classifyChild.vue’ export default new Router({ mode: ’history’, routes: [ { path: ’/classify’, name: ’ classify’, component: classify }, { path: ’/classify/classifyChild’, name: ’classifyChild’, component: classifyChild }, ]})
二、頁(yè)面跳轉(zhuǎn)及傳參
//方式一<router-link :to='{name:’classifyChild’,params:{id:item.id}}'> <button>跳轉(zhuǎn)</button></router-link> //方式二<router-link :to='{path:’/classify/classifyChild’,query:{id:item.id}}'> <button>跳轉(zhuǎn)</button></router-link>
三、參數(shù)接收
//對(duì)應(yīng)于方式一let id=this.$route.params.id; //對(duì)應(yīng)于方式二let id=this.$route.query.id;
補(bǔ)充知識(shí):關(guān)于vue3.0中的this.$router.replace({ path: ’/’})刷新無(wú)效果問(wèn)題
首先在store中定義所需要的變量可以進(jìn)行初始化,再定義一個(gè)方法,登錄成功后A頁(yè)面,跳轉(zhuǎn)到B頁(yè)面之前,需要直接調(diào)用store中存儲(chǔ)數(shù)據(jù)的方法,全局可以使用,順序是,先調(diào)用store中的數(shù)據(jù),其次調(diào)用sessionStorage和localStorage中的數(shù)據(jù)。
這樣的話,可以避免A頁(yè)面跳轉(zhuǎn)B頁(yè)面時(shí)候,手動(dòng)刷新才顯示信息。
直接登錄成功后,直接調(diào)用store的方法,把值存儲(chǔ)進(jìn)去,B頁(yè)面可以直接顯示用戶信息。必須在store定義方法,登錄成功后調(diào)用方法進(jìn)行回顯用戶信息。在這里插入圖片描述
如此一來(lái),就可以避免必須手動(dòng)刷新一下才會(huì)顯示信息。
以上這篇Vue頁(yè)面跳轉(zhuǎn)傳遞參數(shù)及接收方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python中Anaconda3 安裝gdal庫(kù)的方法2. PHP AOP教程案例3. python用zip壓縮與解壓縮4. python公司內(nèi)項(xiàng)目對(duì)接釘釘審批流程的實(shí)現(xiàn)5. Notepad++如何配置python?配置python操作流程詳解6. Python 簡(jiǎn)介7. Python操作Excel工作簿的示例代碼(*.xlsx)8. JAVA如何轉(zhuǎn)換樹結(jié)構(gòu)數(shù)據(jù)代碼實(shí)例9. Python importlib模塊重載使用方法詳解10. Python自動(dòng)化之定位方法大殺器xpath
