Vue this.$router.push(參數(shù))實(shí)現(xiàn)頁面跳轉(zhuǎn)操作
很多情況下,我們?cè)趫?zhí)行點(diǎn)擊按鈕跳轉(zhuǎn)頁面之前還會(huì)執(zhí)行一系列方法,這時(shí)可以使用 this.$router.push(location) 來修改 url,完成跳轉(zhuǎn)。
push 后面可以是對(duì)象,也可以是字符串:
// 字符串
this.$router.push('/home/first')
// 對(duì)象
this.$router.push({ path: '/home/first' })
// 命名的路由
this.$router.push({ name: 'home', params: { userId: wise }})
跳轉(zhuǎn)頁面并傳遞參數(shù)的方法:
1.Params
由于動(dòng)態(tài)路由也是傳遞params的,所以在 this.$router.push() 方法中path不能和params一起使用,否則params將無效。需要用name來指定頁面。
及通過路由配置的name屬性訪問
在路由配置文件中定義參數(shù):
/* router.js 文件*/
import Vue from "vue";
import Router from "vue-router";
import MediaSecond from "@/views/EnterprisePage/MediaMatrix/second"; //資訊列表
Vue.use(Router);
export default new Router({
routes: [ /* 進(jìn)行路由配置 */
{
name: "MediaSecond",
path: "/MediaSecond",
component: MediaSecond
},
]
})
/* 后面還需要接一空行,否則無法通過 ESlint 語法驗(yàn)證 */
通過name獲取頁面,傳遞params:
this.$router.push({ name: 'MediaSecond',params:{artistName:artistName,imgUrl:imgUrl,type:2} })
在目標(biāo)頁面通過this.$route.params獲取參數(shù):
if (this.$route.params.type == 2) {
this.type = apis.getAtistDetails;
} else {
this.type = apis.getMessageList;
}
2.Query
頁面通過path/name和query傳遞參數(shù),該實(shí)例中row為某行表格數(shù)據(jù)
this.$router.push({ name: 'DetailManagement', query: { auditID: row.id, type: '2' } });
this.$router.push({ path: '/DetailManagement', query: { auditID: row.id, type: '2' } });
在目標(biāo)頁面通過this.$route.query獲取參數(shù):
this.$route.query.type
補(bǔ)充知識(shí):vue this.$router.push('./map');無法跳轉(zhuǎn)的問題
<template>
<div style="text-align: center">
<el-button type="primary" style="margin-top: 40vh" @click="onLogin">登錄</el-button>
</div>
</template>
<script>
export default {
name: 'login',
data ()
return {
}
},
methods: {
onLogin:function () {
this.$router.push('./map');
}
},
}
</script>
<style scoped>
</style>
router中是這樣引入的
import map from '@components/map'
點(diǎn)擊事件無法跳轉(zhuǎn)
2.解決方法:
改變引入方式
import map=r=>require.ensure([],()=>(require('../components/map')),'map')
這樣通過靜態(tài)引入就沒問題了!
以上這篇Vue this.$router.push(參數(shù))實(shí)現(xiàn)頁面跳轉(zhuǎn)操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue的elementUI實(shí)現(xiàn)自定義主題方法
下面小編就為大家分享一篇Vue的elementUI實(shí)現(xiàn)自定義主題方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-02-02
Vant picker 多級(jí)聯(lián)動(dòng)操作
這篇文章主要介紹了Vant picker 多級(jí)聯(lián)動(dòng)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11
淺談vue中關(guān)于checkbox數(shù)據(jù)綁定v-model指令的個(gè)人理解
這篇文章主要介紹了淺談vue中關(guān)于checkbox數(shù)據(jù)綁定v-model指令的個(gè)人理解,v-model用于表單的數(shù)據(jù)綁定很常見,下面就來詳細(xì)的介紹一下2018-11-11
vue2更改data里的變量不生效時(shí),深層更改data里的變量問題
這篇文章主要介紹了vue2更改data里的變量不生效時(shí),深層更改data里的變量問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue實(shí)現(xiàn)條件判斷動(dòng)態(tài)綁定樣式的方法
今天小編就為大家分享一篇vue實(shí)現(xiàn)條件判斷動(dòng)態(tài)綁定樣式的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09

