亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

vue跳轉(zhuǎn)頁面的幾種方法(推薦)

瀏覽:2日期:2023-01-29 15:00:03

vue跳轉(zhuǎn)不同頁面的多種方法

1:router-link跳轉(zhuǎn)

<!-- 直接跳轉(zhuǎn) --><router-link to=’/testDemo’> <button>點(diǎn)擊跳轉(zhuǎn)2</button></router-link> <!-- 帶參數(shù)跳轉(zhuǎn) --><router-link :to='{path:’testDemo’,query:{setid:123456}}'> <button>點(diǎn)擊跳轉(zhuǎn)1</button></router-link> <router-link :to='{name:’testDemo’,params:{setid:1111222}}'> <button>點(diǎn)擊跳轉(zhuǎn)3</button></router-link>

2:this.$router.push()

<template> <div id=’test’> <button @click=’goTo()’>點(diǎn)擊跳轉(zhuǎn)4</button> </div></template><script> export default{ name:’test’, methods:{ goTo(){ //直接跳轉(zhuǎn) this.$router.push(’/testDemo’); //帶參數(shù)跳轉(zhuǎn) this.$router.push({path:’/testDemo’,query:{setid:123456}}); this.$router.push({name:’testDemo’,params:{setid:111222}}); } } }</script>

params和query傳參數(shù)有什么不一樣??在地址欄中可以看到,params傳參數(shù)時,地址欄中看不到參數(shù)的內(nèi)容,有點(diǎn)像ajax中的post傳參,query傳參數(shù)時,地址欄中可以看到傳過來的參數(shù)信息,有點(diǎn)像ajax的個體傳參

如果單獨(dú)傳setId一個參數(shù)的時候,地址欄中的地址如下圖:

vue跳轉(zhuǎn)頁面的幾種方法(推薦)

第一種方式:path - query 傳參

vue跳轉(zhuǎn)頁面的幾種方法(推薦)

第二種方式:name - params傳參數(shù)

但是一般情況下,傳參數(shù)是傳遞一個對象,當(dāng)傳遞的是一個對象的時候,地址欄中的地址如下圖:

vue跳轉(zhuǎn)頁面的幾種方法(推薦)

第一種方式:path - query 傳參

vue跳轉(zhuǎn)頁面的幾種方法(推薦)

第二種方式:name - params傳參數(shù)

3:a標(biāo)簽可以跳轉(zhuǎn)么??可以跳轉(zhuǎn)外部鏈接,不能路由跳轉(zhuǎn)

<a ><button>點(diǎn)擊跳轉(zhuǎn)5</button></a>

接收方怎么接收參數(shù)??this.$route.query.serid和this.$route.params.setid,以下舉一個接收的例子

注意接收參數(shù)時是 $route 不是 $router

<template> <div> testDemo{{this.$route.query.setid}} </div></template>

知識點(diǎn)補(bǔ)充:vue三種不同方式實(shí)現(xiàn)頁面跳轉(zhuǎn)

Vue:router-lin

<router-link to='/'>[跳轉(zhuǎn)到主頁]</router-link> <router-link to='/login'>[登錄]</router-link> <router-link to='/logout'>[登出]</router-link>

this.$router.push('/');

<button @click='goHome'>[跳轉(zhuǎn)到主頁]</button>export default { name: 'App', methods: { // 跳轉(zhuǎn)頁面方法 goHome() { this.$router.push('/'); },}

this.$router.go(1);

<button @click='upPage'>[上一頁]</button> <button @click='downPage'>[下一頁]</button> upPage() { // 后退一步記錄,等同于 history.back() this.$router.go(-1); }, downPage() { // 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward() this.$router.go(1); }

代碼示例:

<template> <div id='app'> <img src='http://www.aoyou183.cn/bcjs/assets/logo.png'> <router-view/> <router-link to='/'>[跳轉(zhuǎn)到主頁]</router-link> <router-link to='/login'>[登錄]</router-link> <router-link to='/logout'>[登出]</router-link> <!-- javascript跳轉(zhuǎn)頁面 --> <button @click='goHome'>[跳轉(zhuǎn)到主頁]</button> <!-- 回到上一頁 --> <button @click='upPage'>[上一頁]</button> <button @click='downPage'>[下一頁]</button> <!-- 回到下一頁 --> </div></template> <script> export default { name: 'App', methods: { // 跳轉(zhuǎn)頁面方法 goHome() { this.$router.push('/'); }, upPage() { // 后退一步記錄,等同于 history.back() this.$router.go(-1); }, downPage() { // 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward() this.$router.go(1); } } };</script>

總結(jié)

到此這篇關(guān)于vue不同方法跳轉(zhuǎn)頁面的幾種方法的文章就介紹到這了,更多相關(guān)vue 跳轉(zhuǎn)頁面內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 日韩高清在线免费看 | 国产成人激烈叫床视频 | 韩日在线视频 | 欧美日韩一区二区在线视频播放 | 亚洲精品一区二区中文 | 91看片在线观看 | 夜夜拍夜夜爽夜夜拍拍拍 | 毛片一区二区三区 | 国产免费一级在线观看 | 国产成人亚洲日本精品 | 国产成人免费永久播放视频平台 | 日本特黄高清免费大片爽 | 美女内部福利视频在线观看 | 草逼大片 | 国产成人激情 | 欧美日韩在线观看一区 | 俄罗斯一级成人毛片 | 亚洲无线乱码高清在线观看一区 | 亚洲免费成人网 | 精品国产一区二区三区www | 在线欧美成人 | 澳门一级毛片免费播放 | 国产一区二区三区高清视频 | 国产成人夜间影院在线观看 | 91精品久久一区二区三区 | 免费高清毛片在线播放视频 | 黄色片日韩 | 国产综合视频在线观看一区 | 日本96在线精品视频免费观看 | 成年人黄色大片 | 欧美一级特黄aa大片在线观看免费 | 中国黄色在线观看 | 国产一级做a爱片久久毛片a | 国产精品三级在线播放 | 国产免费午夜a无码v视频 | 精品欧美日韩一区二区三区 | 精品不卡一区中文字幕 | 亚洲福利视频一区二区 | 久久国产亚洲欧美日韩精品 | 亚洲欧美一区二区三区在饯 | 亚洲欧美日韩不卡一区二区三区 |