本篇內容介紹了“vue怎樣實現從A頁面跳轉到B頁面”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
本文操作環境:windows7系統、Vue2.9.6版,DELL G3電腦。
vue怎么實現A頁面跳轉到B頁面?
vue 從A界面跳轉到B界面并攜帶參數
最近遇到一個需求,需要從A界面點擊一個按鈕跳轉到B界面,并且攜帶參數。
我是這樣子實現了需求:
A頁面:
<el-button size="mini" type="success" @click="add" icon="el-icon-plus" round plain>{{$t('common.add')}}</el-button> <el-button type="primary" size="mini" @click="edit" icon="el-icon-edit" plain round>{{ $t('common.edit') }}</el-button>
點擊事件:
add() { this.lockTaskStatus = 'new' this.toLockTaskManagePage()},edit() { this.lockTaskStatus = 'edit' this.toLockTaskManagePage()},toLockTaskManagePage() { this.$router.push({ path: '/taskLockManage', name: 'TaskLockManage', params: { status: this.lockTaskStatus } })}
將將跳轉的url添加到 $router中。
path 中的url 最前面加 / 代表是根目錄下,不加則表示是子路由。
通過path + params的組合傳遞參數。
B頁面:
created() { this.getParams() }, watch: { // 監測路由變化,只要變化了就調用獲取路由參數方法將數據存儲本組件即可 $route: 'getParams' }, methods: { getParams() { // 取到路由帶過來的參數 const res = this.$route.params.status console.log('getParams', res) }}
最后,還需在router/index.js中注冊:
{ path: '/taskLockManage', component: Layout, redirect: '/taskManage/index', hidden: true, children: [ { path: 'taskLockManage', component: () => import('@/views/taskManage/taskLockManage'), name: 'TaskLockManage', meta: { title: 'taskLockManage', icon: 'user', noCache: true } } ]}
這樣,便可實現了跳轉。(PS:這是目前發現的比較好的方法,希望哪位大佬有更好的方法指導。)
“vue怎樣實現從A頁面跳轉到B頁面”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。