vue解決使用webpack打包后keep-alive不生效的方法
問題是這樣的,我使用webpack的npm run dev運行的時候,keep-alive路由緩存是有效的,但是我npm run build,把文件放到實際的項目中去的時候,會有如下的問題:
路由如下:
var menus = [ { path: '/user', name: '用戶', component: '/user', redirect: '/user/index1', icon: 'fa-bandcamp', meta: { keepAlive: false }, children: [ { path: 'index1', component: '/user/index1', name: '用戶管理1', meta: {keepAlive: true}}, { path: 'index2', component: '/user/index2', name: '用戶管理2', meta: {keepAlive: true}}, ] },{ path: '/system', name: 'system', component: '/system', redirect: '/system/index', icon: 'fa-superpowers', noDropdown: true, meta: { keepAlive: false }, children: [ { path: 'index', component: '/system/index', name: '系統(tǒng)管理', meta: {keepAlive: true}}, ] }, ]
我在 /user/index1 和/user/index2 之間做切換的時候路由緩存還是生效的,但是在user和system之間切換的時候就不生效了,解決方法如下,也解釋不清楚什么原因,可能生產(chǎn)環(huán)境下需要在路由的文件上面做緩存把
在route目錄下新建兩個文件:
_import_development.js
module.exports = file => require('@/views/' + file + '.vue')
_import_production.js
module.exports = file => () => import('@/views/' + file + '.vue')
原先路由import的時候是這樣的:
import Home from '@/views/home/homeView'
現(xiàn)在改成這樣:
const _import = require('./_import_' + process.env.NODE_ENV); const Login = _import('index/loginView')
重新打包運行生效!
以上這篇vue解決使用webpack打包后keep-alive不生效的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
- vue 使某個組件不被 keep-alive 緩存的方法
- 解決vue keep-alive 數(shù)據(jù)更新的問題
- vue2使用keep-alive緩存多層列表頁的方法
- 基于vue中keep-alive緩存問題的解決方法
- 詳解關于Vue2.0路由開啟keep-alive時需要注意的地方
- Vue中 key keep-alive的實現(xiàn)原理
- vue 中的keep-alive實例代碼
- vue.js內(nèi)置組件之keep-alive組件使用
- vue keep-alive請求數(shù)據(jù)的方法示例
- vue中keep-alive的用法及問題描述
- vue中進入詳情頁記住滾動位置的方法(keep-alive)
相關文章
Vue通過WebSocket建立長連接的實現(xiàn)代碼
這篇文章主要介紹了Vue通過WebSocket建立長連接的實現(xiàn)代碼,文中給出了問題及解決方案,需要的朋友可以參考下2019-11-11Vue-CLI 3.X 部署項目至生產(chǎn)服務器的方法
這篇文章主要介紹了Vue-CLI 3.X 部署項目至生產(chǎn)服務器的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-03-03