iView-admin 動態(tài)路由問題的解決方法
IView-admin 在使用的時候
跳轉(zhuǎn)客戶詳細(xì)后,點擊其它頁面,然后再從選項卡進(jìn)入頁面時,發(fā)下控制臺 報錯,不能正常打開客戶詳細(xì)頁面
[vue-router] Route with name 'customer/detail/:id' does not exist
地址欄的地址變?yōu)?http://localhost:8080/ 正確的地址為 http://localhost:8080/customer/detail/150
路由器配置如下
{
path: 'detail/:id',
name: 'customer/detail',
meta: {
title: '客戶詳細(xì)',
hideInMenu: true
},
component: () => import('@/view/customer/detail/detail.vue')
}
最后找到原因是,IView-admin 路由跳轉(zhuǎn)使用的是
turnToPage (name) {
if (name.indexOf('isTurnByHref_') > -1) {
window.open(name.split('_')[1])
return
}
this.$router.push({
name: name
})
},
采用 this.$router.push({name: name}) 來跳轉(zhuǎn)
在瀏覽器的Local Storage里發(fā)現(xiàn)是這樣存儲的
{"name":"customer/detail","path":"/customer/detail/150","meta":{"title":"客戶詳細(xì)","hideInMenu":true}}
name 上邊沒有客戶詳細(xì)的ID信息,所以跳轉(zhuǎn)的時候出現(xiàn)了問題。
現(xiàn)將 mian.vue truenToPage 下新增代碼,采用this.$router.push({path: path})方式來跳轉(zhuǎn)
turnToPagePath (path) {
if (name.indexOf('isTurnByHref_') > -1) {
window.open(name.split('_')[1])
return
}
this.$router.push({
path: path
})
},
然后修改 main.vue handleClick 部分代碼
handleClick (item) {
// this.turnToPage(item.name)
this.turnToPagePath(item.path)
}
問題解決
由此引發(fā)了新問題
從列表打開id為150的客戶信息,再從列表打開id為140的客戶信息。從別的頁面點選項卡跳轉(zhuǎn)到客戶詳細(xì)頁面 發(fā)現(xiàn)還是進(jìn)入到 150的客戶信息,而不是最新 140的客戶信息
解決方法,修改 util.js
之前的代碼
export const getNewTagList = (list, newRoute) => {
const { name, path, meta } = newRoute
let newList = [...list]
if (newList.findIndex(item => item.name === name) >= 0) return newList
else newList.push({ name, path, meta })
return newList
}
修改后的代碼
export const getNewTagList = (list, newRoute) => {
const { name, path, meta } = newRoute
let newList = [...list]
let _index = newList.findIndex(item => item.name === name)
if (_index >= 0) {
if (newList[_index].path !== path) { // 如果name已經(jīng)存在,判斷path值
newList[_index].path = path // 如果不一樣,修改path值
}
return newList
} else newList.push({ name, path, meta })
return newList
}
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
Vue3.3?+?TS4構(gòu)建實現(xiàn)ElementPlus功能的組件庫示例
Vue.js?是目前最盛行的前端框架之一,而?TypeScript?則是一種靜態(tài)類型言語,它能夠讓開發(fā)人員在編寫代碼時愈加平安和高效,本文將引見如何運(yùn)用?Vue.js?3.3?和?TypeScript?4?構(gòu)建一個自主打造媲美?ElementPlus?的組件庫2023-10-10
vue實現(xiàn)頁面內(nèi)容禁止選中功能,僅輸入框和文本域可選
今天小編就為大家分享一篇vue實現(xiàn)頁面內(nèi)容禁止選中功能,僅輸入框和文本域可選,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue v-for循環(huán)重復(fù)數(shù)據(jù)無法添加問題解決方法【加track-by=''索引''】
這篇文章主要介紹了vue v-for循環(huán)重復(fù)數(shù)據(jù)無法添加問題解決方法,結(jié)合實例形式分析了vue.js通過在v-for循環(huán)中添加track-by='索引'解決重復(fù)數(shù)據(jù)無法添加問題相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
關(guān)于eslint+prettier+husky的配置及說明
這篇文章主要介紹了關(guān)于eslint+prettier+husky的配置及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
Vue拖拽組件列表實現(xiàn)動態(tài)頁面配置功能
這篇文章主要介紹了Vue拖拽組件列表實現(xiàn)動態(tài)頁面配置功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06

