vue跳轉頁面的幾種常用方法代碼示例
更新時間:2023年10月10日 10:28:18 作者:碩霸天下
這篇文章主要給大家介紹了關于vue跳轉頁面的幾種常用方法,vue跳轉頁面有好幾種不同方法,文中通過代碼將實現(xiàn)的方法介紹的非常詳細,對大家學習或者使用vue具有一定的參考借鑒價值,需要的朋友可以參考下
vue跳轉不同頁面的方法
1.router-link跳轉
<!-- 直接跳轉 -->
<router-link to='/testC'>
<button>點擊跳轉2</button>
</router-link>
<!-- 帶參數(shù)跳轉 -->
<router-link :to="{path:'testC',query:{setid:123456}}">
<button>點擊跳轉1</button>
</router-link>
<router-link :to="{name:'testC',params:{setid:1111222}}">
<button>點擊跳轉3</button>
</router-link>2.this.$router.push()
<template>
<div id='app'>
<button @click='goTo()'>點擊跳轉4</button>
</div>
</template>
<script>
new Vue({
el:'#app',
methods:{
goTo(){
//直接跳轉
this.$router.push('/testDemo');
//帶參數(shù)跳轉
this.$router.push({path:'/testC',query:{setid:123456}});
this.$router.push({name:'testC',params:{setid:111222}});
}
}
})
</script>3.a標簽可以跳轉外部鏈接,不能路由跳轉
<a ><button>點擊跳轉5</button></a>
接收:this.$route.query.serid 和 this.$route.params.setid
vue三種不同方式實現(xiàn)跳轉頁面
Vue:router-link
<router-link to="/">[跳轉到主頁]</router-link>
<router-link to="/login">[登錄]</router-link>
<router-link to="/logout">[登出]</router-link>
this.$router.push("/");this.$router.push("/")
<button @click="goHome">[跳轉到主頁]</button>
export default {
name: "App",
methods: {
// 跳轉頁面方法
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="/">[跳轉到主頁]</router-link>
<router-link to="/login">[登錄]</router-link>
<router-link to="/logout">[登出]</router-link>
<!-- javascript跳轉頁面 -->
<button @click="goHome">[跳轉到主頁]</button>
<!-- 回到上一頁 -->
<button @click="upPage">[上一頁]</button>
<button @click="downPage">[下一頁]</button>
<!-- 回到下一頁 -->
</div>
</template>
<script>
export default {
name: "App",
methods: {
// 跳轉頁面方法
goHome() {
this.$router.push("/");
},
upPage() {
// 后退一步記錄,等同于 history.back()
this.$router.go(-1);
},
downPage() {
// 在瀏覽器記錄中前進一步,等同于 history.forward()
this.$router.go(1);
}
}
};
</script>總結
到此這篇關于vue跳轉頁面的幾種常用方法的文章就介紹到這了,更多相關vue跳轉頁面方法內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue項目打包為APP,靜態(tài)資源正常顯示,但API請求不到數(shù)據(jù)的操作
這篇文章主要介紹了vue項目打包為APP,靜態(tài)資源正常顯示,但API請求不到數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
Vue引入使用localforage改進本地離線存儲方式(突破5M限制)
這篇文章主要介紹了Vue引入使用localforage改進本地離線存儲方式(突破5M限制),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
vue-quill-editor實現(xiàn)圖片上傳功能
這篇文章主要為大家詳細介紹了vue-quill-editor實現(xiàn)圖片上傳功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08
vuex+axios+element-ui實現(xiàn)頁面請求loading操作示例
這篇文章主要介紹了vuex+axios+element-ui實現(xiàn)頁面請求loading操作,結合實例形式分析了vuex+axios+element-ui實現(xiàn)頁面請求過程中l(wèi)oading遮罩層相關操作技巧與使用注意事項,需要的朋友可以參考下2020-02-02

