這篇文章主要介紹vue-router2.0跳轉(zhuǎn)之router.push()的使用方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

router.push(location)
除了使用 創(chuàng)建 a 標簽來定義導航鏈接,我們還可以借助 router 的實例方法,通過編寫代碼來實現(xiàn)。
router.push(location)
想要導航到不同的 URL,則使用 router.push 方法。這個方法會向 history 棧添加一個新的記錄,所以,當用戶點擊瀏覽器后退按鈕時,則回到之前的 URL。
當你點擊 <router-link> 時,這個方法會在內(nèi)部調(diào)用,所以說,點擊 等同于調(diào)用 router.push(…)。
聲明式:<router-link :to="...">
編程式:router.push(...)
該方法的參數(shù)可以是一個字符串路徑,或者一個描述地址的對象。
// 字符串
router.push('home')
// 對象
this.$router.push({path: '/login?url=' + this.$route.path});
// 命名的路由
router.push({ name: 'user', params: { userId: 123 }})
// 帶查詢參數(shù),變成/backend/order?selected=2
this.$router.push({path: '/backend/order', query: {selected: "2"}});
// 設(shè)置查詢參數(shù)
this.$http.post('v1/user/select-stage', {stage: stage})
.then(({data: {code, content}}) => {
if (code === 0) {
// 對象
this.$router.push({path: '/home'});
}else if(code === 10){
// 帶查詢參數(shù),變成/login?stage=stage
this.$router.push({path: '/login', query:{stage: stage}});
}
});
// 設(shè)計查詢參數(shù)對象
let queryData = {};
if (this.$route.query.stage) {
queryData.stage = this.$route.query.stage;
}
if (this.$route.query.url) {
queryData.url = this.$route.query.url;
}
this.$router.push({path: '/my/profile', query: queryData});
網(wǎng)頁題目:vue-router2.0跳轉(zhuǎn)之router.push()的使用方法-創(chuàng)新互聯(lián)
鏈接分享:http://chinadenli.net/article28/dheejp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、外貿(mào)建站、品牌網(wǎng)站設(shè)計、移動網(wǎng)站建設(shè)、標簽優(yōu)化、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容