欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue跳轉(zhuǎn)頁面打開新窗口,并攜帶與接收參數(shù)方式

 更新時(shí)間:2022年04月09日 16:49:20   作者:一羊遷徙  
這篇文章主要介紹了vue跳轉(zhuǎn)頁面打開新窗口,并攜帶與接收參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

1、攜帶普通類型參數(shù)

字符串、數(shù)字等。

path:要跳轉(zhuǎn)新頁面的路由鏈接

query:要攜帶的參數(shù)

let pathInfo = this.$router.resolve({
? path:'/product_detail',
? ? ?query:{
? ? ? ? ?productId:'11'
? ? ?}
?})
?window.open(pathInfo.href, '_blank');

新頁面的參數(shù)接收:

this.productId = this.$route.query.productId

2、攜帶復(fù)雜類型參數(shù)

對(duì)象、數(shù)組等,通過JSON轉(zhuǎn)換進(jìn)行傳遞。

let pathInfo = this.$router.resolve({
? ?path:'/product_detail',
? ? ?query:{
? ? ? ? ?data:{name:'張三'}
? ? ?}
?})
?window.open(pathInfo.href, '_blank');

新頁面的參數(shù)接收:

console.log(this.$route.query.data)

vue頁面跳轉(zhuǎn)并傳參的八種方式

我們知道,在vue中每個(gè)頁面都需要在路由中聲明,就是在router/index.js中寫下面代碼:

import Vue from 'vue'
import Router from 'vue-router'
import Test from "../components/Test";
Vue.use(Router)
export default new Router({
? mode: 'history',
? routes: [
?? ??? ? ?{
?? ??? ? ? ? ?path: '/t',
?? ??? ? ? ? ?name: 'Test',
?? ??? ? ? ? ?component: Test,
?? ??? ? ? ? ?hidden:true
?? ??? ? ? ?},
? ? ?? ?]
? ? })

實(shí)現(xiàn)頁面跳轉(zhuǎn)并傳參有多種方式:

方法一

在template中可以使用<router-link>標(biāo)簽實(shí)現(xiàn)跳轉(zhuǎn),跳轉(zhuǎn)的路徑是http://localhost:8080/t?index=id,如下:

<router-link to="/t?index=1">
? ? ?<button class="btn btn-default">點(diǎn)擊跳轉(zhuǎn)</button>
</router-link>

只需要點(diǎn)擊按鈕就可以實(shí)現(xiàn)跳轉(zhuǎn),不需要寫js代碼,需要傳遞參數(shù)的話只需要/t?index=1即可,這樣的話跳轉(zhuǎn)的頁面獲取參數(shù)通過window.location.href能夠獲取到完整的url,然后截取參數(shù)。也可以通過下面代碼獲取參數(shù)

this.$route.query.index

方法二

跳轉(zhuǎn)的路徑是http://localhost:8080/t?index=id

<router-link :to="{path:'/t',query: {index: 1}}">
? ? ?<button class="btn btn-default">點(diǎn)擊跳轉(zhuǎn)</button>
</router-link>

其中需要注意,這里的to前面一定要加冒號(hào),path的值要和上面路由定義的值一致,傳參用query,里面是參數(shù)字典。

接收參數(shù):

this.$route.query.index

方法三

命名路由的方式:

跳轉(zhuǎn)的路徑是http://localhost:8080/t?index=id

<router-link :to="{name:'Test',params: {index: 1}}">
? ? ?<button class="btn btn-default">點(diǎn)擊跳轉(zhuǎn)</button>
</router-link>

注意這里的name也要和router/index.js中聲明的name值一致,并且傳參使用params,和name配對(duì)的是params,和path配對(duì)的是query。

接收參數(shù):

this.$route.params.index

方法四

跳轉(zhuǎn)的路徑是http://localhost:8080/t/id

<router-link:to="'/test/'+1">
? ? ?<button class="btn btn-default">點(diǎn)擊跳轉(zhuǎn)</button>
</router-link>

這時(shí)的路由也需要更為為下面的形式:

routes: [
?? ??? ? ?{
?? ??? ? ? ? ?path: '/t/:index',
?? ??? ? ? ? ?name: 'Test',
?? ??? ? ? ? ?component: Test,
?? ??? ? ? ? ?hidden:true
?? ??? ? ? ?},
? ? ?? ?]

接收參數(shù):

this.$route.params.index

方法五

上面四種方法都是在html中實(shí)現(xiàn)的跳轉(zhuǎn),還有另外對(duì)應(yīng)的在js中實(shí)現(xiàn)的跳轉(zhuǎn)并傳參的方法,代碼如下:

<template>
<button @click = "func()">跳轉(zhuǎn)</button>
</template>
<script>
? ? export default{
? ? ? ? methods:{
? ? ? ? ? ? func (){
? ? ? ? ? ? ? ? this.$router.push({path: '/t?index=1'});
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>

接收參數(shù)依然使用

this.$route.query.index

方法六

<template>
<button @click = "func()">跳轉(zhuǎn)</button>
</template>
<script>
? ? export default{
? ? ? ? methods:{
? ? ? ? ? ? func (){
? ? ? ? ? ? ? ? this.$router.push({path: '/t',query:{ index:'1'}});
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>

接收參數(shù)依然使用

this.$route.query.index

方法七

<template>
<button @click = "func()">跳轉(zhuǎn)</button>
</template>
<script>
? ? export default{
? ? ? ? methods:{
? ? ? ? ? ? func (){
? ? ? ? ? ? ? ? this.$router.push({path: '/t/index'});
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>

接收參數(shù)依然使用

this.$route.query.index

方法八

<template>
<button @click = "func()">跳轉(zhuǎn)</button>
</template>
<script>
? ? export default{
? ? ? ? methods:{
? ? ? ? ? ? func (){
? ? ? ? ? ? ? ? this.$router.push({name: 'Test',params:{ index:'1'}});
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>

接收參數(shù)依然使用

this.$route.params.index

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

  • 詳解Vue實(shí)現(xiàn)直播功能

    詳解Vue實(shí)現(xiàn)直播功能

    這篇文章主要介紹了Vue實(shí)現(xiàn)直播功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè))

    vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè))

    vue 是一個(gè)完全支持組件化開發(fā)的框架, 組件之間可以進(jìn)行相互的引用,這篇文章主要介紹了vue中注冊(cè)組件的兩種方式詳解(全局注冊(cè)&& 局部注冊(cè)),需要的朋友可以參考下
    2023-06-06
  • vue項(xiàng)目接口訪問地址設(shè)置方式

    vue項(xiàng)目接口訪問地址設(shè)置方式

    這篇文章主要介紹了vue項(xiàng)目接口訪問地址設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • vue3實(shí)現(xiàn)多條件搜索功能的示例代碼

    vue3實(shí)現(xiàn)多條件搜索功能的示例代碼

    搜索功能在后臺(tái)管理頁面中非常常見,這篇文章就著重講一下vue3-admin-element框架中如何實(shí)現(xiàn)一個(gè)頂部多條件搜索功能,感興趣的小伙伴可以了解一下
    2023-08-08
  • 詳解mpvue中小程序自定義導(dǎo)航組件開發(fā)指南

    詳解mpvue中小程序自定義導(dǎo)航組件開發(fā)指南

    這篇筆記主要記錄一下基于mpvue的小程序中實(shí)現(xiàn)自定義導(dǎo)航的思路及應(yīng)用。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • vue中引用文件路徑問題小結(jié)

    vue中引用文件路徑問題小結(jié)

    vue路徑分為絕對(duì)路徑、相對(duì)路徑、~+路徑?及?別名+路徑,在js中,引入帶別名的文件路徑,不需要在別名前加~?,在css或者style中引入的需要在路徑前面加~,路徑以?~?開頭,其后的部分將會(huì)被看作模塊依賴,本文給大家介紹vue中引用文件路徑問題,感興趣的朋友一起看看吧
    2023-12-12
  • 詳解vue-flickity的fullScreen功能實(shí)現(xiàn)

    詳解vue-flickity的fullScreen功能實(shí)現(xiàn)

    這篇文章主要介紹了詳解vue-flickity的fullScreen功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • vue+element-ui集成隨機(jī)驗(yàn)證碼+用戶名+密碼的form表單驗(yàn)證功能

    vue+element-ui集成隨機(jī)驗(yàn)證碼+用戶名+密碼的form表單驗(yàn)證功能

    在登入頁面,我們往往需要通過輸入驗(yàn)證碼才能進(jìn)行登入,那我們下面就詳講一下在vue項(xiàng)目中如何配合element-ui實(shí)現(xiàn)這個(gè)功能,需要的朋友可以參考下
    2018-08-08
  • Vue結(jié)合后臺(tái)導(dǎo)入導(dǎo)出Excel問題詳解

    Vue結(jié)合后臺(tái)導(dǎo)入導(dǎo)出Excel問題詳解

    這篇文章主要介紹了Vue結(jié)合后臺(tái)導(dǎo)入導(dǎo)出Excel問題詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • 詳解vuex中的this.$store.dispatch方法

    詳解vuex中的this.$store.dispatch方法

    這篇文章主要介紹了vuex中的this.$store.dispatch方法,必須要用commit(‘SET_TOKEN’,?tokenV)調(diào)用mutations里的方法,才能在store存儲(chǔ)成功,需要的朋友可以參考下
    2022-11-11

最新評(píng)論