国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue解決使用webpack打包后keep-alive不生效的方法

2019-11-19 13:04:29
字體:
供稿:網(wǎng)友

問題是這樣的,我使用webpack的npm run dev運(yùn)行的時(shí)候,keep-alive路由緩存是有效的,但是我npm run build,把文件放到實(shí)際的項(xiàng)目中去的時(shí)候,會(huì)有如下的問題:

路由如下:

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 之間做切換的時(shí)候路由緩存還是生效的,但是在user和system之間切換的時(shí)候就不生效了,解決方法如下,也解釋不清楚什么原因,可能生產(chǎn)環(huán)境下需要在路由的文件上面做緩存把

在route目錄下新建兩個(gè)文件:

_import_development.js

module.exports = file => require('@/views/' + file + '.vue')

_import_production.js

module.exports = file => () => import('@/views/' + file + '.vue')

原先路由import的時(shí)候是這樣的:

import Home from '@/views/home/homeView'

現(xiàn)在改成這樣:

const _import = require('./_import_' + process.env.NODE_ENV);const Login = _import('index/loginView')

重新打包運(yùn)行生效!

以上這篇vue解決使用webpack打包后keep-alive不生效的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 柘荣县| 如东县| 民和| 武义县| 西和县| 香格里拉县| 夏津县| 阿拉善盟| 苗栗市| 顺昌县| 江口县| 当涂县| 宁明县| 宜都市| 湖北省| 凤阳县| 奈曼旗| 棋牌| 拜城县| 临武县| 治县。| 大同市| 景洪市| 海宁市| 清新县| 彰化市| 瑞昌市| 淮阳县| 祁连县| 岳普湖县| 剑河县| 靖西县| 红原县| 碌曲县| 济阳县| 甘南县| 新龙县| 息烽县| 平南县| 黔西县| 广安市|