解決elementUi使用導航菜單的時候,重複點擊報錯的問題

相信只要使用vue+elmentUI 做後臺管理系統的 基本上都需要用到左側導航欄

然後左側導航欄和路由導航 聯繫在一起

默認它是不啓用 路由關聯的 這個時候我們得配置一下 纔可以

給el-menu上面加一個  router的屬性纔可以 關聯到

<el-menu :default-active="$router.currentRoute.path" router class="el-menu-slide">
</el-menu>

還有就是一個問題 就是重複點擊導航的時候 就會報錯

在這裏插入圖片描述

雖然 不影響 項目的使用 但是對開發人員 很難受哈 特別是我這種強迫症患者

下面給出 解決方法
先給出 vue.ts 版本的
將下面的代碼 放到 router/index.js 的new VueRouter() 上面 記住

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location:any) {
  return (originalPush.call(this, location) as any).catch((err:any) => err)
}
// 這個上面哈  
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes:asyncRouterMap
})

vue.js版本 的

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location:any) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes:asyncRouterMap
})

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章