vue跳轉(zhuǎn)頁面的幾種常用方法實例總結(jié)
更新時間:2024年05月28日 10:12:32 作者:戰(zhàn)斗天使ZCY
Vue是一種流行的JavaScript框架,用于構(gòu)建用戶界面,在Vue中,頁面跳轉(zhuǎn)通常使用路由(Router)來實現(xiàn),除此之外還有很多方法,這篇文章主要給大家介紹了關(guān)于vue跳轉(zhuǎn)頁面的幾種常用方法,需要的朋友可以參考下
vue跳轉(zhuǎn)不同頁面的方法
1.router-link跳轉(zhuǎn)
<!-- 直接跳轉(zhuǎn) -->
<router-link to='/testC'>
<button>點擊跳轉(zhuǎn)2</button>
</router-link>
<!-- 帶參數(shù)跳轉(zhuǎn) -->
<router-link :to="{path:'testC',query:{setid:123456}}">
<button>點擊跳轉(zhuǎn)1</button>
</router-link>
<router-link :to="{name:'testC',params:{setid:1111222}}">
<button>點擊跳轉(zhuǎn)3</button>
</router-link>2.this.$router.push()
<template>
<div id='app'>
<button @click='goTo()'>點擊跳轉(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>點擊跳轉(zhuǎn)5</button></a>
接收:this.$route.query.serid 和 this.$route.params.setid
vue三種不同方式實現(xiàn)跳轉(zhuǎn)頁面
Vue:router-link
<router-link to="/">[跳轉(zhuǎn)到主頁]</router-link>
<router-link to="/login">[登錄]</router-link>
<router-link to="/logout">[登出]</router-link>
this.$router.push("/");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() {
// 在瀏覽器記錄中前進一步,等同于 history.forward()
this.$router.go(1);
}代碼示例:
<template>
<div id="app">
<img src="./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() {
// 在瀏覽器記錄中前進一步,等同于 history.forward()
this.$router.go(1);
}
}
};
</script>總結(jié)
到此這篇關(guān)于vue跳轉(zhuǎn)頁面的幾種常用方法的文章就介紹到這了,更多相關(guān)vue跳轉(zhuǎn)頁面方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在vue項目中 實現(xiàn)定義全局變量 全局函數(shù)操作
這篇文章主要介紹了在vue項目中 實現(xiàn)定義全局變量 全局函數(shù)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
Vue3+Ant?design?實現(xiàn)Select下拉框一鍵全選/清空功能
在做后臺管理系統(tǒng)項目的時候,產(chǎn)品增加了一個在Select選擇器中添加一鍵全選和清空的功能,他又不讓在外部增加按鈕,其實如果說在外部增加按鈕實現(xiàn)全選或者清空的話,功能比較簡單的,下面給大家分享Vue3+Ant?design?實現(xiàn)Select下拉框一鍵全選/清空功能,需要的朋友可以參考下2024-05-05
vue3+vue-cli4中使用svg的方式詳解(親測可用)
最近在做個vue的項目,從各種github上的開源庫上借鑒開發(fā)方法,給大家分享下,這篇文章主要給大家介紹了關(guān)于vue3+vue-cli4中使用svg的相關(guān)資料,需要的朋友可以參考下2022-08-08
vue使用v-for循環(huán)獲取數(shù)組最后一項
這篇文章主要介紹了vue使用v-for循環(huán)獲取數(shù)組最后一項問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
完美解決vue 中多個echarts圖表自適應(yīng)的問題
這篇文章主要介紹了完美解決vue 中多個echarts圖表自適應(yīng)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07

