vue-element-admin配置讲解

  1. 项目初始化
    1.git clone https://github.com/PanJiaChen/vue-element-admin
    2.cd vue-element-admin
    3.npm install
    4.npm run dev
  2. 项目精简
    删除scr/views下的源码, 保留:
    1.dashboard:首页
    2.error-page:异常页面
    3.login:登录
    4.redirect:重定向
    对src/router/index 进行相应修改

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

  /* Layout */
 import Layout from '@/layout'
 /**
* Note: sub-menu only appear when route children.length >= 1
* Detail see: https://panjiachen.github.io/vue-element-admin- 
 site/guide/essentials/router-and-nav.html
*
* hidden: true                   if set true, item will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu
*                                if not set alwaysShow, when item has more than one children route,
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
roles: ['admin','editor']    control the page roles (you can set multiple roles)
title: 'title'               the name show in sidebar and breadcrumb (recommend set)
icon: 'svg-name'             the icon show in the sidebar
noCache: true                if set true, the page will no be cached(default is false)
affix: true                  if set true, the tag will affix in the tags-view
breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
}
*/

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
*/
 export const constantRoutes = [
     {
       path: '/redirect',
       component: Layout,
       hidden: true,
      children: [
    {
         path: '/redirect/:path(.*)',
         component: () => import('@/views/redirect/index')
     }
  ]
},
{
   path: '/login',
   component: () => import('@/views/login/index'),
   hidden: true
},
{
  path: '/auth-redirect',
  component: () => import('@/views/login/auth-redirect'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () => import('@/views/error-page/401'),
  hidden: true
},
{
   path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [
    {
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
    }
   ]
  }
]

 /**
  * asyncRoutes
  * the routes that need to be dynamically loaded based on user roles
  */
export const asyncRoutes = [
     // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
 ]

const createRouter = () => new Router({
   // mode: 'history', // require service support
   scrollBehavior: () => ({ y: 0 }),
   routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment- 357941465
export function resetRouter() {
 const newRouter = createRouter()
 router.matcher = newRouter.matcher // reset router
}

   export default router

3.删除 src/router/modules 文件夹

4.删除 src/vendor文件夹

  1. 项目配置
    进入src目录下的settings.js配置文件

    module.exports = {
         title: 'Project Title',
         showSettings: true,
         tagsView: true,
         fixedHeader: false,
         sidebarLogo: false,
         errorLog: 'production'
     }
    

3.1 项目标题
在src/settings.js 配置项目标题
标题旁边的图标在public里面修改

image.png

image.png

3.2 showSettings
showSettings用来设置是否显示控制面板,设置为false则不显示


image.png

3.3 tagsView
tagsView是我们打开某个页面是否有页面标签

image.png

3.4 fixedHeader
fixedHeader是内容页面向下滑动时头部是否固定,false是不固定, true是固定


image.png

3.5 sidebarLogo
sidebarLogo控制菜单栏上方是否显示图标

image.png

3.6 源码调试
打开vue.config.js文件
找到如下图的位置


image.png

cheap-source-map调试模式没有完全编译展示我们的源代码

我们改成source-map调试模式,这时候再来看Sources的App.vue文件,已经和源代码显示的一样,在这样的环境下调试我们会更加方便
但是source-map有一个缺点,每当我们程序有改动时,也需要同步生成source-map文件,这样会使我们构建变慢,在实际开发过程中推荐使用eval,以增加构建速度 在需要调试的时候使用source-map

  1. 项目结构分析

api :接口请求
assets :一些静态文件
components : 封装组件
direcetive :自定义指令
filters :过滤器
icons :图标
layout :全局框架组件(非常重要)
router :路由
store :配置vuex
styles :全局样式文件
utils :工具类
views :页面组件
App.vue :父组件,其他的组件都是嵌套在App.vue里
main.js :全局入口文件,将App.vue设置为全局父组件进行渲染
permissions.js :登录的校验和登录之后的路由跳转
setting.js :配置文件

原文链接:https://blog.csdn.net/pjsdsg/java/article/details/104918098

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,117评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,963评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,897评论 0 240
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,805评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,208评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,535评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,797评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,493评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,215评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,477评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,988评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,325评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,971评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,807评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,544评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,455评论 2 266