vue-element-admin配置小结

 更新时间:2022年04月28日 09:22:44   作者:盲流子开发  
本文主要介绍了vue-element-admin配置小结,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

1. 项目初始化

git clone https://github.com/PanJiaChen/vue-element-admin
cd vue-element-admin
npm install 
npm run dev  

2. 项目精简

删除scr/views下的源码, 保留:

  • dashboard:首页
  • error-page:异常页面
  • login:登录
  • 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

删除 src/router/modules 文件夹

删除 src/vendor文件夹

3. 项目配置

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

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

3.1 项目标题

在src/settings.js 配置项目标题

在这里插入图片描述

在这里插入图片描述

3.2 showSettings

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

在这里插入图片描述

3.3 tagsView

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

3.4 fixedHeader

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

在这里插入图片描述

3.5 sidebarLogo

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

在这里插入图片描述

3.6 源码调试

打开vue.config.js文件

找到如下图的位置

在这里插入图片描述

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

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

在这里插入图片描述

4. 项目结构分析

在这里插入图片描述

  • 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 :配置文件

到此这篇关于vue-element-admin配置小结的文章就介绍到这了,更多相关vue-element-admin配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue如何移动到指定位置(scrollIntoView)亲测避坑

    vue如何移动到指定位置(scrollIntoView)亲测避坑

    这篇文章主要介绍了vue如何移动到指定位置(scrollIntoView)亲测避坑,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • vue项目如何读取本地json文件数据实例

    vue项目如何读取本地json文件数据实例

    很多时候我们需要从本地读取JSON文件里面的内容,这篇文章主要给大家介绍了关于vue项目如何读取本地json文件数据的相关资料,需要的朋友可以参考下
    2023-06-06
  • vue.js表单验证插件(vee-validate)的使用教程详解

    vue.js表单验证插件(vee-validate)的使用教程详解

    这篇文章主要介绍了vue.js表单验证插件(vee-validate)的使用,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-05-05
  • vue移动端实现红包雨效果

    vue移动端实现红包雨效果

    这篇文章主要为大家详细介绍了vue移动端实现红包雨效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-07-07
  • vue实现树状表格效果

    vue实现树状表格效果

    这篇文章主要为大家详细介绍了vue实现树状表格效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-12-12
  • 关于vant的时间选择器使用方式

    关于vant的时间选择器使用方式

    这篇文章主要介绍了关于vant的时间选择器使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-03-03
  • Vue项目服务器部署刷新页面404问题及解决

    Vue项目服务器部署刷新页面404问题及解决

    这篇文章主要介绍了Vue项目服务器部署刷新页面404问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-09-09
  • 在移动端使用vue-router和keep-alive的方法示例

    在移动端使用vue-router和keep-alive的方法示例

    这篇文章主要介绍了在移动端使用vue-router和keep-alive的方法示例,vue-router与keep-alive提供的路由体验与移动端是有一定差别的,感兴趣的小伙伴们可以参考一下
    2018-12-12
  • VUE中的v-if与v-show区别介绍

    VUE中的v-if与v-show区别介绍

    这篇文章介绍了VUE中v-if与v-show的区别,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-03-03
  • ubuntu中利用nginx部署vue项目的完整步骤

    ubuntu中利用nginx部署vue项目的完整步骤

    Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行,下面这篇文章主要给大家介绍了关于ubuntu中利用nginx部署vue项目的相关资料,需要的朋友可以参考下
    2022-02-02

最新评论