vue+antd 页面热重载失败

问题描述

vue+antd  页面热重载失败
项目启动后,在动态路由新建页面,命令台执行编译后,模块加载失败 一直处于50%多 Ctrl+C后项目正常启动,端口号变更

问题出现的环境背景及自己尝试过哪些方法

JeecgBoot 是一款基于代码生成器的低代码开发平台

更改配置路由

相关代码

粘贴代码文本(请勿用截图)


permisison.js

import Vue from 'vue'

import router from './router'

import store from './store'

import NProgress from 'nprogress' // progress bar

import 'nprogress/nprogress.css' // progress bar style

import notification from 'ant-design-vue/es/notification'

import { ACCESS_TOKEN,INDEX_MAIN_PAGE_PATH, OAUTH2_LOGIN_PAGE_PATH } from '@/store/mutation-types'

import { generateIndexRouter, isOAuth2AppEnv } from '@/utils/util'

NProgress.configure({ showSpinner: false }) // 进度条禁用,设置 showSpinner 为 false

const whiteList = ['/user/login', '/user/register-process', '/user/register', '/user/register-result','/user/alteration'] // no redirect whitelist

whiteList.push(OAUTH2_LOGIN_PAGE_PATH)

router.beforeEach((to, from, next) => {

NProgress.start() // start progress bar

if (Vue.ls.get(ACCESS_TOKEN)) {

/* has token */

if (to.path === '/user/login' || to.path === OAUTH2_LOGIN_PAGE_PATH) {

next({ path: INDEX_MAIN_PAGE_PATH })

NProgress.done()

} else {

if (store.getters.permissionList.length === 0) {

store.dispatch('GetPermissionList').then(res => {

const menuData = res.result.menu;

//console.log(res.message)

if (menuData === null || menuData === "" || menuData === undefined) {

return;

}

let constRoutes = [];

constRoutes = generateIndexRouter(menuData);

// 添加主界面路由

store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {

// 根据roles权限生成可访问的路由表

// 动态添加可访问路由表

router.addRoutes(store.getters.addRouters)

const redirect = decodeURIComponent(from.query.redirect || to.path)

if (to.path === redirect) {

// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record

next({ ...to, replace: true })

} else {

// 跳转到目的路由

next({ path: redirect })

}

})

})

.catch(() => {

/* notification.error({

message: '系统提示',

description: '请求用户信息失败,请重试!'

})*/

store.dispatch('Logout').then(() => {

next({ path: '/user/login', query: { redirect: to.fullPath } })

})

})

} else {

next()

}

}

} else {

if (whiteList.indexOf(to.path) !== -1) {

// 在免登录白名单,如果进入的页面是login页面并且当前是OAuth2app环境,就进入OAuth2登录页面

if (to.path === '/user/login' && isOAuth2AppEnv()) {

next({path: OAUTH2_LOGIN_PAGE_PATH})

} else {

// 在免登录白名单,直接进入

next()

}

NProgress.done()

} else {

// 如果当前是在OAuth2APP环境,就跳转到OAuth2登录页面

let path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : '/user/login'

next({ path: path, query: { redirect: to.fullPath } })

NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it

}

}

})

router.afterEach(() => {

NProgress.done() // finish progress bar

})

util.js

// 生成首页路由

export function generateIndexRouter(data) {

let indexRouter = [{

path: '/',

name: 'dashboard',

//component: () => import('@/components/layouts/BasicLayout'),

component: resolve => require(['@/components/layouts/TabLayout'], resolve),

meta: { title: '首页' },

redirect: '/index/index',

children: [

...generateChildRouters(data)

]

},{

"path": "*", "redirect": "/404", "hidden": true

}]

return indexRouter;

}

// 生成嵌套路由(子路由)

function generateChildRouters (data) {

const routers = [];

for (let item of data) {

let component = "";

if(item.component.indexOf("layouts")>=0){

component = "components/"+item.component;

}else{

component = "views/"+item.component;

}

// eslint-disable-next-line

let URL = (item.meta.url|| '').replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)) // URL支持{{ window.xxx }}占位符变量

if (isURL(URL)) {

item.meta.url = URL;

}

let componentPath

componentPath = resolve => require(['@/' + component+'.vue'], resolve)

let menu = {

path: item.path,

name: item.name,

redirect:item.redirect,

component: componentPath,

//component: resolve => require(['@/' + component+'.vue'], resolve),

hidden:item.hidden,

//component:()=> import(`@/views/${item.component}.vue`),

meta: {

title:item.meta.title ,

icon: item.meta.icon,

url:item.meta.url ,

permissionList:item.meta.permissionList,

keepAlive:item.meta.keepAlive,

/*update_begin author:wuxianquan date:20190908 for:赋值 */

internalOrExternal:item.meta.internalOrExternal,

/*update_end author:wuxianquan date:20190908 for:赋值 */

componentName:item.meta.componentName

}

}

if(item.alwaysShow){

menu.alwaysShow = true;

menu.redirect = menu.path;

}

if (item.children && item.children.length > 0) {

menu.children = [...generateChildRouters( item.children)];

}

//--update-begin----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------

//判断是否生成路由

if(item.route && item.route === '0'){

//console.log(' 不生成路由 item.route: '+item.route);

//console.log(' 不生成路由 item.path: '+item.path);

}else{

routers.push(menu);

}

//--update-end----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------

}

return routers

}

你期待的结果是什么?想知道是哪里的问题

新增页面刷新路由后 命令台正常运行

以上是 vue+antd 页面热重载失败 的全部内容, 来源链接: utcz.com/p/937533.html

回到顶部