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

您的位置:首頁技術文章
文章詳情頁

Vue this.$router.push(參數)實現頁面跳轉操作

瀏覽:3日期:2022-11-25 14:20:49

很多情況下,我們在執行點擊按鈕跳轉頁面之前還會執行一系列方法,這時可以使用 this.$router.push(location) 來修改 url,完成跳轉。

push 后面可以是對象,也可以是字符串:

// 字符串this.$router.push(’/home/first’)// 對象this.$router.push({ path: ’/home/first’ })// 命名的路由this.$router.push({ name: ’home’, params: { userId: wise }})

跳轉頁面并傳遞參數的方法:

1.Params

由于動態路由也是傳遞params的,所以在 this.$router.push() 方法中path不能和params一起使用,否則params將無效。需要用name來指定頁面。

及通過路由配置的name屬性訪問

在路由配置文件中定義參數:

/* 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: [ /* 進行路由配置 */ { name: 'MediaSecond', path: '/MediaSecond', component: MediaSecond }, ]}) /* 后面還需要接一空行,否則無法通過 ESlint 語法驗證 */

通過name獲取頁面,傳遞params:

this.$router.push({ name: ’MediaSecond’,params:{artistName:artistName,imgUrl:imgUrl,type:2} })

在目標頁面通過this.$route.params獲取參數:

if (this.$route.params.type == 2) { this.type = apis.getAtistDetails;} else { this.type = apis.getMessageList;}

2.Query

頁面通過path/name和query傳遞參數,該實例中row為某行表格數據

this.$router.push({ name: ’DetailManagement’, query: { auditID: row.id, type: ’2’ } });

this.$router.push({ path: ’/DetailManagement’, query: { auditID: row.id, type: ’2’ } });

在目標頁面通過this.$route.query獲取參數:

this.$route.query.type

補充知識:vue this.$router.push(’./map’);無法跳轉的問題

<template> <div style='text-align: center'> <el-button type='primary' @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’

點擊事件無法跳轉

2.解決方法:

改變引入方式

import map=r=>require.ensure([],()=>(require(’../components/map’)),’map’)

這樣通過靜態引入就沒問題了!

以上這篇Vue this.$router.push(參數)實現頁面跳轉操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 岢岚县| 唐河县| 孙吴县| 金塔县| 黔西县| 宜兰市| 江孜县| 济宁市| 深圳市| 古丈县| 靖西县| 金湖县| 乐亭县| 福海县| 凤凰县| 临夏县| 新邵县| 大厂| 汝州市| 中西区| 十堰市| 新和县| 崇礼县| 新乐市| 迭部县| 房山区| 陇西县| 洱源县| 始兴县| 灵寿县| 敦煌市| 马鞍山市| 烟台市| 辉南县| 普兰店市| 商南县| 乐清市| 邻水| 班玛县| 嵊泗县| 黎平县|