最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iView-admin 動態(tài)路由問題的解決方法

 更新時間:2018年10月03日 10:26:30   作者:彥楨  
這篇文章主要介紹了iView-admin 動態(tài)路由問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

 IView-admin 在使用的時候

跳轉(zhuǎn)客戶詳細(xì)后,點(diǎn)擊其它頁面,然后再從選項(xiàng)卡進(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的客戶信息。從別的頁面點(diǎn)選項(xiàng)卡跳轉(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)文章

最新評論

尼木县| 宁城县| 通榆县| 高州市| 竹溪县| 宜都市| 福贡县| 翁牛特旗| 闸北区| 虎林市| 广灵县| 长汀县| 尉犁县| 柳河县| 府谷县| 清河县| 武川县| 永安市| 浙江省| 明水县| 平泉县| 克拉玛依市| 苍山县| 偏关县| 谢通门县| 玛沁县| 曲阜市| 绥芬河市| 五台县| 栾川县| 历史| 洛阳市| 措美县| 贡嘎县| 灵武市| 大同县| 长寿区| 乐昌市| 阿坝| 九龙坡区| 司法|