tft每日頭條

 > 圖文

 > vue項目中如何實現路由跳轉

vue項目中如何實現路由跳轉

圖文 更新时间:2025-02-11 14:32:31

<button @click="tiaozhuan">去到新的頁面</button> <button @click="go">前進</button> <button @click="back">後退</button> methods: { tiaozhuan(){ // this.$router.push({name:'me'}) //組件name跳轉 // this.$router.push({path:'/me/text'}) //組件path跳轉 // this.$router.push({name:'weather',params:{city:'北京'}}) //組件name跳轉 帶參數 如果使用name路由并且需要傳遞參數,需要搭配params一起 // this.$router.push({path:'/weather/天津',params:{city:'北京'}}) //天津 兩種參數都存在的時候,path中的參數會起作用 // this.$router.push({path:'/weather/北京?username=jia&password=123456'}) //傳值 this.$router.push({path:'/weather/牡丹江',query:{username:'jiajia',password:123456}}) //傳值 分開寫會自動拼接到path中 // this.$router.replace({path:'/weather/牡丹江',query:{username:'jiajia',password:123456}},()=>{ // console.log('成功替換了頁面,replace有回調函數') // }) //去到了path頁面後,不能回退到上一個頁面,回退的隻能是浏覽器标簽頁 // console.log(this) }, go(){ this.$router.go(1)//前進 數字可根據情況定義 history不夠的話,是失敗的 }, back(){ this.$router.go(-1)//後退 } },

vue項目中如何實現路由跳轉(vue中動态路由的跳轉)1

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关圖文资讯推荐

热门圖文资讯推荐

网友关注

Copyright 2023-2025 - www.tftnews.com All Rights Reserved