Vue学习笔记: Vue + Element-ui搭建后台管理系统模板
Vue学习笔记: Vue + Element-ui搭建后台管理系统模板
技术:Vue + Element-ui
功能:后台管理系统基础模板,路由配置,加载页面进度条,请求响应拦截器的封装等
页面预览:后台管理系统模板
代码:GitHub
一、创建初始化项目
选择好项目所在文件夹:进入cmds输入 vue create zhb_vue_cli
zhb_vue_cli为自定义项目名称;
如果不需要太多功能的话可以选择快速创建。选择第一个直接回车,进行项目创建;
cmd窗口输入命令 cd zhb_vue_cli 回车进入 vueinit001 项目中,再输入 npm run serve 回车启动服务
1.1.4、浏览器地址栏输入 http://localhost:8080/ ,正常打开网页表示项目创建成功
二、建立相应目录结构,配置路由
详细介绍几个文件
1、package.json
package.json文件是项目配置文件,除了项目的一些基本信息外,注意一下三点:
(1)dependencies:项目发布时的依赖
(2)devDependencies:项目开发时的依赖
(3)scripts:编译项目的一些命令
2、main.js
这里是入口文件,可以引入一些插件或静态资源,当然引入之前要先安装了该插件,在package.json文件中有记录。
3、App.vue
这是一个标准的vue组件,包含三个部分,一个是模板,一个是script,一个是样式,这里需要了解vue的基础。
三、封装请求拦截响应等
import axios from 'axios'
import { Message } from 'element-ui'
import router from '@/router';const service = axios.create({timeout: 20000
})
/** 添加请求拦截器 **/
service.interceptors.request.use(config => {if (localStorage.getItem('token')) {config.headers['token'] = localStorage.getItem('token')}if (config.method == 'post') {config.headers['Content-Type'] = 'application/json'}if (config.data instanceof FormData) {config.headers = {'Content-Type': 'multipart/form-data','token':localStorage.getItem('token')}}return config},error => {console.log(error)return Promise.reject(error)}
)// 这里的conut 是为了防止tokne失效导致太多提示框弹出
let count = 0
/** 添加响应拦截器 **/
service.interceptors.response.use(response => {const res = response.data;if (res.code != 20000) {if (res.code == 30001) {if (count === 0) {Message({message: "身份验证过期,请重新登录!",type: "error",});}localStorage.removeItem("token")router.push({ path: '/login', query: { path: router.currentRoute.fullPath } })}// else if (res.code == 10001) {// Message.error(res.msg);// }count++return Promise.reject(res)} else {return res}},error => {if (count === 0) {if( error.response.data.code == "30001" ){Message({message: '登录令牌失效,请重新登录',type: 'error',duration: 3 * 1000})count = 0;localStorage.removeItem("token")router.push({ path: '/login', query: { path: router.currentRoute.fullPath } })}else{Message({message: error.message,type: 'error',duration: 5 * 1000})}}count++return Promise.reject(error)}
)export default service
四、配置路由
import Vue from 'vue';
import VueRouter from 'vue-router';Vue.use(VueRouter);const routes = [{path: '/',redirect: '/login'},{path: '/login',name: "login",component: () =>import('@/views/Login.vue'),},{path: '/',name: "index",component: () => import('@/layout/admin.vue'),meta: { title: 'admin' },children:[{path: '/index',name: "index",component: () => import('@/views/index.vue'),meta: { title: '系统首页' },},{path: '/user',name: "user",component: () => import('@/views/user.vue'),meta: { title: '用户' },},{path: '/portal',name: "portal",component: () => import('@/views/portal.vue'),meta: { title: '门户管理' },},{path: '/edit',name: "edit",component: () => import('@/views/edit.vue'),meta: { title: '富文本编辑器' },},]},
]
export default new VueRouter({base: process.env.BASE_URL,routes
})
五、封装菜单组件和头部组件
代码详情:请在GitHub下载项目
组装:
六、预览页面
学习小记,仅供参考,如有疑问请一键三连;若有bug之处,恳请同仁多多指教!!!
Vue学习笔记: Vue + Element-ui搭建后台管理系统模板相关推荐
- vue学习笔记-关于element ui 安装失败的问题解决
今天学习vue时,对element ui进行安装,运行npm install element-ui -S 命令,出现报错: npm ERR! code ERESOLVE npm ERR! ERESOL ...
- Vue学习笔记:Element时间控件设置某一个日期禁止选择
Vue学习笔记:Element时间控件添加一段时间禁止选择 需求:时间控件,当天之前禁止选择,某一个日期的之前时间禁止选择 文档: 代码实现:在时间控件上添加 :picker-options=&quo ...
- Vue3+TS+Vite+Element Plus搭建后台管理系统
Vue3+TS+Vite+Element Plus搭建后台管理系统 1.简介 2.效果图 3.技术栈 4.项目目录 5.setting.js(全局配置文件) 6.路由router 7.状态管理stor ...
- vue + element ui 的后台管理系统框架_从零开始搭建 VUE + Element UI后台管理系统框架...
点击右上方红色按钮关注"web秀",让你真正秀起来 前言 后台管理系统前端框架,现在很流行的形式都是,上方和左侧都是导航菜单,中间是具体的内容.比如阿里云.七牛云.头条号.百家号等 ...
- vue+element ui 项目 后台管理系统
前端界面 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF ...
- Vue学习笔记--Vue双向绑定实现原理
我们知道Vue可以实现数据双向绑定,Angular和Vue都是采用的MVVM 模式,意思就是当M(模型层)层数据进行修改时,VM层会监测到变化,并且通知V(视图层)层进行相应的修改,反之修改V层则会通 ...
- Vue学习笔记-Vue数据绑定
v-bind 只能实现Vue单项数据绑定 <div id="databaind"> 单项数据绑定:<input :value="name" t ...
- element ui 前台模板_SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(二):引入 element-ui 定义基本页面显示...
前提: (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y ...
- 「Vue 学习笔记 1」Vue 项目快速搭建,初始项目各个文件夹作用介绍和启动代码执行流程分析
「Vue 学习笔记 1」Vue 项目快速搭建,初始项目各个文件夹作用介绍和启动代码执行流程分析 前言 一.我的开发环境 二.使用 Vue CLI (Vue 脚手架)快速搭建项目 三.初始项目的目录结构 ...
最新文章
- ajax cors html,通过CORS通过Ajax请求在浏览器上设置Cookie
- 0-100之间的素数、判断素数的基本和优化方法
- Erlang转JAVA,将Erlang UTF-8编码的字符串转换为java.lang.String
- cookie 跨域问题
- Cloudera maneger登录页面后的操作是什么?
- Buildroot stress-ng Linux系统压力测试
- 【2018新年巨献】像阿里巴巴一样高效工作!(含视频、文章、PDF文件)
- DockOne技术分享:十个问题带你了解Windows Docker
- oracle 空值的排序问题 (转载),sqlserver、oracle数据库排序空值null问题解决办法
- Hive SemanticException
- 电脑主页面上的计算机没了,电脑界面上的internet explorer 没有了
- IDEA——使用JSONObject时报错怎么办?
- thinkphp __hash__
- 兼容IE8以下,获取className节点的元素(document.getElementsByClassName()兼容写法)。
- OPPO A37M刷机
- Windows 10 运行python弹出windows应用商店
- 用计算机寻找规律,用计算器找规律练习题
- MySQL主从一致的校验
- 机房收费系统之简单的逻辑(上)下机费用运算
- Migrating to the New Material Buttons and their Themes