admin-element-vue切換頁簽會刷新問題


使用admin-element-vue的頁簽時,會發現切換頁簽會自動刷新頁面,其實也可以不刷新的

1、在src\layout\components\AppMain.vue里

<router-view :key="key">
   <router-view />
</router-view>
改為
<keep-alive>
  <router-view :key="key" />
</keep-alive>

2、在頁面的name和路由的name名字要一樣

 

 

如果想切換頁簽時刷新頁面,可以在路由上加上:noCache: true

   path: '/home',
    component: Layout,
    redirect: '/home',
    alwaysShow: true,
    name: 'home',
    meta: { title: 'home', noCache: true, icon: 'home', roles: 'home' },
    children: []

如果切換想觸發某個事件,可以在activated里面加

當引入keep-alive的時候,頁面第一次進入,鈎子的觸發順序created-> mounted-> activated,退出時觸發deactivated。當再次進入(前進或者后退)時,只觸發activated
created() {
     console.log(1)
},
mounted() {
     console.log(2)
},
activated:() {
     console.log(3)
},
deactivated:() {
     console.log(4)
}

參考:https://www.jianshu.com/p/42429f4d8f9e

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM