vue解决使用webpack打包后keep-alive不生效的方法
网络编程 2021-07-04 16:46www.168986.cn编程入门
今天长沙网络推广就为大家分享一篇vue解决使用webpack打包后keep-alive不生效的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧
问题是这样的,我使用webpack的npm run dev运行的时候,keep-alive路由缓存是有效的,但是我npm run build,把文件放到实际的项目中去的时候,会有如下的问题:
路由如下:
var menus = [ { path: '/user', name: '用户', ponent: '/user', redirect: '/user/index1', icon: 'fa-bandcamp', meta: { keepAlive: false }, children: [ { path: 'index1', ponent: '/user/index1', name: '用户管理1', meta: {keepAlive: true}}, { path: 'index2', ponent: '/user/index2', name: '用户管理2', meta: {keepAlive: true}}, ] },{ path: '/system', name: 'system', ponent: '/system', redirect: '/system/index', icon: 'fa-superpowers', noDropdown: true, meta: { keepAlive: false }, children: [ { path: 'index', ponent: '/system/index', name: '系统管理', meta: {keepAlive: true}}, ] }, ]
我在 /user/index1 和/user/index2 之间做切换的时候路由缓存还是生效的,但是在user和system之间切换的时候就不生效了,解决方法如下,也解释不清楚什么原因,可能生产环境下需要在路由的文件上面做缓存把
在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'
现在改成这样:
const _import = require('./_import_' + process.env.NODE_ENV); const Login = _import('index/loginView')
重新打包运行生效!
以上这篇vue解决使用webpack打包后keep-alive不生效的方法就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程