vue?點(diǎn)擊按鈕?路由跳轉(zhuǎn)指定頁面的實(shí)現(xiàn)方式
點(diǎn)擊按鈕 路由跳轉(zhuǎn)指定頁面
最終效果
點(diǎn)擊指定按鈕,跳轉(zhuǎn)指定 /login 頁面

代碼:
<button @click="gotolink" class="btn btn-success">點(diǎn)擊跳轉(zhuǎn)頁面</button>
methods:{
gotolink(){
//點(diǎn)擊跳轉(zhuǎn)至上次瀏覽頁面
// this.$router.go(-1)
//指定跳轉(zhuǎn)地址
this.$router.replace('/login')
}
}vue跳轉(zhuǎn)頁面常用的方式
vue跳轉(zhuǎn)頁面有好幾種不同方法,下面將通過實(shí)例代碼給大家介紹,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下。
1:router-link跳轉(zhuǎn)
1.不帶參數(shù)
<router-link :to="{name:'home'}">?
<router-link :to="{path:'/home'}"> //name,path都行, 建議用name?
// 注意:router-link中鏈接如果是'/'開始就是從根路由開始;如果不帶'/',則從當(dāng)前路由開始。
2.帶params參數(shù)
<router-link :to="{name:'home', params: {id:123456}}">?
// params傳參數(shù) (類似post)
// 路由配置 path: "/home/:id" 或者 path: "/home:id"?
// 不配置path ,第一次可請求,刷新頁面id會消失;配置path,刷新頁面id會保留。
// html 取參 $route.params.id ? ?script 取參 this.$route.params.id
3.帶query參數(shù)
<router-link :to="{name:'home', query: {id:123456}}">?
// query傳參數(shù) (類似get,url后面會顯示參數(shù))
// 路由可不配置
// html 取參 $route.query.id ? ?script 取參 this.$route.query.id2:this.$router.push()
1.不帶參數(shù)
this.$router.push('/home')
this.$router.push({name:'home'})
this.$router.push({path:'/home'})
2.query傳參
this.$router.push({name:'home',query: {id:'123456'}})
this.$router.push({path:'/home',query: {id:'123456'}})
// html 取參 $route.query.id ? ?script 取參 this.$route.query.id
3.params傳參
this.$router.push({name:'home',params: {id:'123456'}}) // 只能用 name
// 路由配置 path: "/home/:id" 或者 path: "/home:id" ,
// 不配置path ,第一次可請求,刷新頁面id會消失
// 配置path,刷新頁面id會保留
// html 取參 $route.params.id ? ?script 取參 this.$route.params.id
4.query和params區(qū)別
query類似get, 跳轉(zhuǎn)之后頁面url后面會拼接參數(shù),類似?id=123456, 非重要性的可以這樣傳, 密碼之類還是用params刷新頁面id還在
params類似post, 跳轉(zhuǎn)之后頁面url后面不會拼接參數(shù), 但是刷新頁面id會消失。
3:this.$router.replace()
用法同上,和第2個的this.$router.push方法一樣。
4:this.$router.go(n)
<button @click="upPage">[上一頁]</button>
<button @click="downPage">[下一頁]</button>
upPage() {
this.$router.go(-1); ?// 后退一步記錄,等同于 history.back()
},
downPage() {
this.$router.go(1); ? // 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward()
}向前或者向后跳轉(zhuǎn)n個頁面,n可為正整數(shù)或負(fù)整數(shù)
ps : 區(qū)別
this.$router.push
跳轉(zhuǎn)到指定url路徑,并向history棧中添加一個記錄,點(diǎn)擊后退會返回到上一個頁面。
this.$router.replace
跳轉(zhuǎn)到指定url路徑,但是history棧中不會有記錄,點(diǎn)擊返回會跳轉(zhuǎn)到上個頁面 (直接替換當(dāng)前頁面)。
this.$router.go(n)
向前或者向后跳轉(zhuǎn)n個頁面,n可為正整數(shù)或負(fù)整數(shù)。
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
- vue跳轉(zhuǎn)頁面的幾種常用方法代碼示例
- vue實(shí)現(xiàn)頁面跳轉(zhuǎn)和參數(shù)傳遞的兩種方式
- 解決vue項(xiàng)目跳轉(zhuǎn)同樣的頁面不刷新的問題思路詳解
- Vue路由跳轉(zhuǎn)傳參或打開新頁面跳轉(zhuǎn)的方法總結(jié)
- vue3頁面跳轉(zhuǎn)的兩種方式
- vue中如何攜帶參數(shù)跳轉(zhuǎn)頁面
- Vue實(shí)現(xiàn)路由跳轉(zhuǎn)至外界頁面
- vue項(xiàng)目中路由跳轉(zhuǎn)頁面不變問題及解決
- vue跳轉(zhuǎn)頁面打開新窗口,并攜帶與接收參數(shù)方式
- vue如何跳轉(zhuǎn)到其他頁面
相關(guān)文章
基于electron+vue3+ts搭建桌面端應(yīng)用并且可以熱更新
這篇文章主要為大家詳細(xì)介紹了如何基于electron+vue3+ts搭建桌面端應(yīng)用并且可以熱更新,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考下2023-10-10
Vue3 + CSS實(shí)現(xiàn)一個噴火龍動畫效果
不知不覺中,2023年已然逝去了,龍年到了,所以本文小編使用Vue3 + CSS實(shí)現(xiàn)一個噴火龍的動畫效果,文中有相關(guān)的代碼示例供大家參考,具有一定的參考價值,感興趣的同學(xué)可以自己動手嘗試一下2024-02-02
vue中v-if?和v-permission?共同使用的坑及解決方案
這篇文章主要介紹了vue中v-if?和v-permission?共同使用的坑及解決方案的相關(guān)資料,需要的朋友可以參考下2023-07-07
關(guān)于配置babel-plugin-import報(bào)錯的坑及解決
這篇文章主要介紹了關(guān)于配置babel-plugin-import報(bào)錯的坑及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
vue/cli3.0腳手架部署到nginx時頁面空白的問題及解決
這篇文章主要介紹了vue/cli3.0腳手架部署到nginx時頁面空白的問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10

