vue跳轉(zhuǎn)頁(yè)面的幾種常用方法實(shí)例總結(jié)
vue跳轉(zhuǎn)不同頁(yè)面的方法
1.router-link跳轉(zhuǎn)
<!-- 直接跳轉(zhuǎn) -->
<router-link to='/testC'>
<button>點(diǎn)擊跳轉(zhuǎn)2</button>
</router-link>
<!-- 帶參數(shù)跳轉(zhuǎn) -->
<router-link :to="{path:'testC',query:{setid:123456}}">
<button>點(diǎn)擊跳轉(zhuǎn)1</button>
</router-link>
<router-link :to="{name:'testC',params:{setid:1111222}}">
<button>點(diǎn)擊跳轉(zhuǎn)3</button>
</router-link>2.this.$router.push()
<template>
<div id='app'>
<button @click='goTo()'>點(diǎn)擊跳轉(zhuǎn)4</button>
</div>
</template>
<script>
new Vue({
el:'#app',
methods:{
goTo(){
//直接跳轉(zhuǎn)
this.$router.push('/testDemo');
//帶參數(shù)跳轉(zhuǎn)
this.$router.push({path:'/testC',query:{setid:123456}});
this.$router.push({name:'testC',params:{setid:111222}});
}
}
})
</script>3.a標(biāo)簽可以跳轉(zhuǎn)外部鏈接,不能路由跳轉(zhuǎn)
<a rel="external nofollow" ><button>點(diǎn)擊跳轉(zhuǎn)5</button></a>
接收:this.$route.query.serid 和 this.$route.params.setid
vue三種不同方式實(shí)現(xiàn)跳轉(zhuǎn)頁(yè)面
Vue:router-link
<router-link to="/">[跳轉(zhuǎn)到主頁(yè)]</router-link>
<router-link to="/login">[登錄](méi)</router-link>
<router-link to="/logout">[登出]</router-link>
this.$router.push("/");this.$router.push("/")
<button @click="goHome">[跳轉(zhuǎn)到主頁(yè)]</button>
export default {
name: "App",
methods: {
// 跳轉(zhuǎn)頁(yè)面方法
goHome() {
this.$router.push("/");
},
}this.$router.go(1)
<button @click="upPage">[上一頁(yè)]</button>
<button @click="downPage">[下一頁(yè)]</button>
upPage() {
// 后退一步記錄,等同于 history.back()
this.$router.go(-1);
},
downPage() {
// 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward()
this.$router.go(1);
}代碼示例:
<template>
<div id="app">
<img src="./assets/logo.png">
<router-view/>
<router-link to="/">[跳轉(zhuǎn)到主頁(yè)]</router-link>
<router-link to="/login">[登錄](méi)</router-link>
<router-link to="/logout">[登出]</router-link>
<!-- javascript跳轉(zhuǎn)頁(yè)面 -->
<button @click="goHome">[跳轉(zhuǎn)到主頁(yè)]</button>
<!-- 回到上一頁(yè) -->
<button @click="upPage">[上一頁(yè)]</button>
<button @click="downPage">[下一頁(yè)]</button>
<!-- 回到下一頁(yè) -->
</div>
</template>
<script>
export default {
name: "App",
methods: {
// 跳轉(zhuǎn)頁(yè)面方法
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)頁(yè)面的幾種常用方法的文章就介紹到這了,更多相關(guān)vue跳轉(zhuǎn)頁(yè)面方法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue內(nèi)置動(dòng)態(tài)組件component使用示例小結(jié)
component是vue內(nèi)置組件,主要作用為動(dòng)態(tài)渲染組件,這篇文章主要介紹了vue內(nèi)置動(dòng)態(tài)組件component使用示例小結(jié),需要的朋友可以參考下2024-03-03
Vue3項(xiàng)目pc端瀏覽器樣式正常但移動(dòng)端部分樣式失效問(wèn)題的解決方法
這篇文章主要介紹了Vue3項(xiàng)目pc端瀏覽器樣式正常但移動(dòng)端部分樣式失效問(wèn)題的解決方法,文中通過(guò)圖文講解的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2024-07-07
在 Vue 3 中上傳 KML 文件并在地圖上顯示的實(shí)現(xiàn)方法
KML 文件作為一種標(biāo)準(zhǔn)的地理數(shù)據(jù)格式,廣泛應(yīng)用于地理信息系統(tǒng)(GIS)中,通過(guò) OpenLayers 和 Vue 3 的組合,您可以方便地實(shí)現(xiàn)地圖數(shù)據(jù)的可視化和交互,本文介紹在 Vue 3 中上傳 KML 文件并在地圖上顯示的實(shí)現(xiàn)方法,感興趣的朋友一起看看吧2024-12-12
vue實(shí)現(xiàn)導(dǎo)航菜單和編輯文本的示例代碼
這篇文章主要介紹了vue實(shí)現(xiàn)導(dǎo)航菜單和編輯文本功能的方法,文中示例代碼非常詳細(xì),幫助大家更好的參考和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
vue3接口數(shù)據(jù)賦值對(duì)象,渲染報(bào)錯(cuò)問(wèn)題及解決
這篇文章主要介紹了vue3接口數(shù)據(jù)賦值對(duì)象,渲染報(bào)錯(cuò)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09

