vue跳轉(zhuǎn)方式(打開(kāi)新頁(yè)面)及傳參操作示例
本文實(shí)例講述了vue跳轉(zhuǎn)方式(打開(kāi)新頁(yè)面)及傳參操作。分享給大家供大家參考,具體如下:
1. router-link跳轉(zhuǎn)
// 直接寫上跳轉(zhuǎn)的地址
<router-link to="/detail/one">
<span class="spanfour" >link跳轉(zhuǎn)</span>
</router-link>
// 添加參數(shù)
<router-link :to="{path:'/detail/two', query:{id:1,name:'vue'}}">
</router-link>
// 參數(shù)獲取
id = this.$route.query.id
// 新窗口打開(kāi)
<router-link :to="{path:'/detail/three', query:{id:1,name:'vue'}}" target="_blank">
</router-link>
2. this.$router.push跳轉(zhuǎn)
toDeail (e) {
this.$router.push({path: "/detail", query: {id: e}})
}
// 參數(shù)獲取
id = this.$route.query.id
toDeail (e) {
this.$router.push({name: "/detail", params: {id: e}})
}
// 注意地址需寫在 name后面
//參數(shù)獲取,params和query區(qū)別,query參數(shù)在地址欄顯示,params的參數(shù)不在地址欄顯示
id = this.$route.params.id
3. this.$router.replace跳轉(zhuǎn)
//和push的區(qū)別,push有記錄一個(gè)history,replace沒(méi)有
toDeail (e) {
this.$router.replace({name: '/detail', params: {id: e}})
}
4. resolve跳轉(zhuǎn)
//resolve頁(yè)面跳轉(zhuǎn)可用新頁(yè)面打開(kāi)
//2.1.0版本后,使用路由對(duì)象的resolve方法解析路由,可以得到location、router、href等目標(biāo)路由的信息。得到href就可以使用window.open開(kāi)新窗口了(這邊應(yīng)用:https://segmentfault.com/q/1010000009557100下的一個(gè)回答)
toDeail (e) {
const new = this.$router.resolve({name: '/detail', params: {id: e}})
window.open(new.href,'_blank')
}
接收方怎么接收參數(shù) this.$route.query.serid和this.$route.params.setid,以下舉一個(gè)接收的例子
注意接收參數(shù)時(shí)是 $route 不是 $router
<template>
<div>
testDemo{{this.$route.query.setid}}
</div>
</template>
接收的參數(shù):
<template>
<div>userlist--{{mallCode}} </div>
</template>
<script>
export default {
name: "UserList",
date:function(){
return {"mallCode":mallCode}
},
created(){
this.getParams()
},
methods:{
getParams() {
// 取到路由帶過(guò)來(lái)的參數(shù)
const routerParams = this.$route.query.mallCode;
this.mallCode = routerParams;
console.log(this.$route.query);
// 將數(shù)據(jù)放在當(dāng)前組件的數(shù)據(jù)內(nèi)
//this.mallInfo.searchMap.mallCode = routerParams;
//this.keyupMallName()
}
}
}
</script>
<style scoped>
</style>
希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
相關(guān)文章
vue使用el-table篩選tree樹形結(jié)構(gòu)的數(shù)據(jù)問(wèn)題
這篇文章主要介紹了vue使用el-table篩選tree樹形結(jié)構(gòu)的數(shù)據(jù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
vue3使用useMouseInElement實(shí)現(xiàn)圖片局部放大預(yù)覽效果實(shí)例代碼
現(xiàn)在很多的項(xiàng)目里面圖片展示縮略圖,然后點(diǎn)擊實(shí)現(xiàn)圖片預(yù)覽,放大的功能,下面這篇文章主要給大家介紹了關(guān)于vue3使用useMouseInElement實(shí)現(xiàn)圖片局部放大預(yù)覽效果的相關(guān)資料,需要的朋友可以參考下2023-03-03
Vue Element前端應(yīng)用開(kāi)發(fā)之echarts圖表
在我們做應(yīng)用系統(tǒng)的時(shí)候,往往都會(huì)涉及圖表的展示,綜合的圖表展示能夠給客戶帶來(lái)視覺(jué)的享受和數(shù)據(jù)直觀體驗(yàn),同時(shí)也是增強(qiáng)客戶認(rèn)同感的舉措之一2021-05-05
Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
Vue-Router實(shí)現(xiàn)頁(yè)面正在加載特效方法示例
這篇文章主要給大家介紹了利用Vue-Router實(shí)現(xiàn)頁(yè)面正在加載特效方法示例,文中給出了詳細(xì)的示例代碼,相信對(duì)大家具有一定的參考價(jià)值,有需要的朋友們下面來(lái)一起看看吧。2017-02-02
讓 babel webpack vue 配置文件支持智能提示的方法
這篇文章主要介紹了讓 babel webpack vue 配置文件支持智能提示的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06

