router-index.jd-全局守卫

import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'Vue.use(VueRouter)const routes = [// 登录页面{path: '/',redirect: "/login",},{path: '/login',name: 'login_view',component: () => import('../views/LoginView.vue')},// 主页面{path: '/home',name: 'home_view',component: () => import('../views/HomeView.vue'),children: [{// 添加页面path: "/list",name: "list_view",component: () => import("../views/UserListView.vue")},{path: '/sanlian',name: "sanlian_view",component: () => import('../views/SanLianView.vue')},]}
]const router = new VueRouter({routes
})export default router
// 全局守卫
router.beforeEach((to, from, next) => {if (to.path == '/login') return next();let token = store.state.userInfo.token;if (!token) return next("/login");next()
})

store-index.js

import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)export default new Vuex.Store({state: {userInfo: sessionStorage.userInfo ? JSON.parse(sessionStorage.userInfo) : ""},getters: {},mutations: {// 写登录的时候写saveInfo(state, userInfo) {state.userInfo = userInfo// 存到本地sessionStorage.setItem("userInfo", JSON.stringify(userInfo))},// 清除token--退出登录的时候写delInfo(state) {state.userInfo = "";// 清除本地信息sessionStorage.removeItem("userInfo")}},actions: {},modules: {}
})

main.js-请求拦截器

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 引入axios
import axios from 'axios'
// 行政区划三级选择
import RegionSelect from './views/SanLianView.vue'
// 行政区划三级选择
Vue.use(RegionSelect)
// 行政区划三级选择
Vue.component('regionSelect', RegionSelect)// element
Vue.use(ElementUI);Vue.config.productionTip = false
// 将aixos配置vue原型中--全局都可以使用
Vue.prototype.$http = axios// 配置全局请求路径
axios.defaults.baseURL = 'http://www.wuhaijun888.com:8888/api/private/v1/';
// 添加请求拦截器---写完登录的时候再写
axios.interceptors.request.use(function (config) {// 在发送请求之前添加tokenif (store.state.userInfo.token) {config.headers.Authorization = store.state.userInfo.token;}return config
}, function (error) {// 对请求错误做些什么return Promise.reject(error);
});new Vue({router,store,render: h => h(App)
}).$mount('#app')

App.vue

<template><div id="app"><router-view/></div>
</template><style lang="scss"></style>

主页面--父页面-----------------------------

<template><div><el-container><el-header><span> <b>后台管理</b> </span><span class="right_btn">{{ $store.state.userInfo.username }}<el-button type="info" @click="logout">退出登录</el-button></span></el-header><el-container><el-aside width="200px"><p><router-link to="/list">用户管理</router-link></p><p><router-link to="/list">权限管理</router-link></p></el-aside><!-- 注意占位符 --><el-main><router-view /> </el-main></el-container></el-container></div>
</template>
<script>
export default {name: "home_view",data() {return {};},methods: {// 回到登录页面---退出登录写logout() {this.$store.commit("delInfo");// 跳转登录页面this.$router.push("/login");},},
};
</script>
<style>
.right_btn {float: right;
}
.el-header,
.el-footer {background-color: #b3c0d1;color: #333;text-align: center;height: 60px;line-height: 60px;
}.el-aside {background-color: #d3dce6;color: #333;text-align: center;height: 600px;
}.el-main {background-color: #e9eef3;color: #333;text-align: center;height: 600px;
}body > .el-container {margin-bottom: 40px;
}.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {line-height: 260px;
}.el-container:nth-child(7) .el-aside {line-height: 320px;
}
</style>

登录页面--子页面

<template><div class="login_mtk"><p>用户名: <input type="text" v-model="username" /></p><p>密码: <input type="password" v-model="password" /></p><el-button type="primary" @click="deng">登录</el-button><el-button type="primary">取消</el-button></div>
</template><script>
export default {name: "login_view",data() {return {username: "admin",password: "123456",};},methods: {// 登录deng() {this.$http.post("/login", {username: this.username,password: this.password,}).then((response) => {let { data: res } = response;console.log(res);// 保存数据this.$store.commit("saveInfo", res.data);// 跳转页面this.$router.push("/home");});},},
};
</script><style>
.login_mtk {width: 300px;height: 300px;border-radius: 20px;background: paleturquoise;position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin:  auto;
}
</style>

添加显示页面---子页面

<template><!-- userList要与下面对应数组 --><div class="userList"><!-- 添加 --><div class="top_add"><span><input type="text" v-model="query" /><el-button type="primary" icon="el-icon-search" @click="sousuo">搜索</el-button></span><el-button class="el-icon-plus" @click="addWindow = true"></el-button></div><!-- 添加--- --><!-- 表单 --><div class="main"><table border="1px"><thead><th>序号</th><th>用户名</th><th>邮箱</th><th>电话</th><th>角色</th><th>操作</th></thead><tbody><tr v-for="(item, index) in userList" :key="item.id"><td>{{ index + 1 }}</td><td>{{ item.username }}</td><td>{{ item.email }}</td><td>{{ item.mobile }}</td><td>{{ item.role_name }}</td><td><el-button class="el-icon-delete" @click="del(item.id)">删除</el-button><el-button class="el-icon-edit" @click="edit(item.id)">编辑</el-button></td></tr></tbody></table></div><!-- 表单完 --><!-- 分页 --><div class="block"><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="currentPage":page-sizes="[2, 4, 6, 8]":page-size="pageSize"layout="total, sizes, prev, pager, next, jumper":total="total"></el-pagination></div><!-- 添加模态框 --><div class="addmtk" v-if="addWindow"><p>用户名: <input type="text" v-model="addForm.username" /></p><p>密码: <input type="password" v-model="addForm.password" /></p><p>邮箱: <input type="text" v-model="addForm.email" /></p><p>电话: <input type="text" v-model="addForm.mobile" /></p><el-button class="el-icon-close" @click="addWindow = false">取消</el-button><el-button class="el-icon-check" type="primary" @click="add">确定</el-button></div><!-- 添加模态框完 --><!-- 编辑模态框 --><div class="editmtk" v-if="editWindow"><p>用户名: <input type="text" v-model="editForm.username" disabled/></p><p>邮箱: <input type="text" v-model="editForm.email" /></p><p>电话: <input type="text" v-model="editForm.mobile" /></p><el-button class="el-icon-close" @click="editWindow = false">取消</el-button><el-button class="el-icon-check" type="primary" @click="editAdd">确定</el-button></div><!-- 编辑模态框完 --></div>
</template>
<script>
export default {name: "list_view",data() {return {userList: [],addForm: {},addWindow: false, //显示隐藏添加模态框editForm: {},editWindow: false,query: "", //搜索currentPage: 1, //默认第几页pageSize: 5,    //默认每页显示几条数据total: 0,};},created() {this.getUserList();},methods: {// 渲染函数==============================================================getUserList() {this.$http.get("/users?" +`pagenum=${this.currentPage},&pagesize=${this.pageSize},&query=${this.query}`).then((response) => {let { data: res } = response;if (res.meta.status == 200) {this.userList = res.data.users;this.total = res.data.total;}});},// 删除==================================================================================del(id) {this.$http.delete("/users/" + id).then(() => {this.getUserList();});},// 添加=======================================================================================async add() {console.log(this);let { data: res } = await this.$http.post("/users", this.addForm);console.log(res);if (res.meta.status == 201) {this.getUserList();// 关闭窗口this.addWindow = false;this.addForm = {};}},// 编辑回显==========================================================================================edit(id) {this.$http.get("/users/" + id).then((response) => {let { data: res } = response;this.editForm = res.data;this.editWindow = true;});},// 编辑提交=============async editAdd() {let { data: res } = await this.$http.put("/users/" + this.editForm.id,this.editForm);if (res.meta.status == 200) {// 关闭编辑窗口this.editWindow = false;this.getUserList();}},// 搜索============================================================sousuo() {this.getUserList();},// 分页====================================================handleSizeChange(val) {this.pageSize = val;this.getUserList();},handleCurrentChange(val) {this.currentPage = val;this.getUserList();},},
};
</script>
<style>
table {width: 100%;
}
.top_add {float: right;
}
/* addmtk */
.addmtk {width: 400px;height: 400px;border-radius: 20px;background: paleturquoise;position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;
}
.editmtk {width: 400px;height: 400px;border-radius: 20px;background: paleturquoise;position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;
}
</style>

| Element 详情相关推荐

  1. Excel数据驱动框架实战

    由于该测试框架是我在工作的系统中搭建的,故不写系统网址,重点记录搭建的框架过程与重点介绍,方便以后察看. 一.系统介绍: 1)在系统中进行登陆 2)在系统登陆的情况下,进行新增操作 3)在新增的数据中 ...

  2. vue+element模仿腾讯视频电影网站(二),增加视频播放详情页

    一.前言 1. 本项目在线预览:点击访问 2. 作者其他博客成品汇总预览:点击访问 3. 接上一篇:<vue+element模仿腾讯视频电影网站> 暂时源码并没有提供其他获取渠道,私聊作者 ...

  3. element基础详情页-文本描述组件

    前端登顶之巅–全方位为你梳理前端进阶之路.最全前端知识/面试点总结 最新版本element-ui 已支持详情描述组件,直接使用即可. 前言 对于常做topB系统的小伙伴们,基础信息详情页是最常见不过的 ...

  4. Vue轮播缩略图(element ui)+鼠标悬浮放大图片(PicZoom)商城详情页图片展示

    效果: PicZoom.vue(图片放大组件) <template><divclass="magnifier-box":class="vertical? ...

  5. Laravel Dcat-admin 详情页多栏布局开发

    背景 随着 dcat-admin 越来越多的人使用,相信有许多跟我一样热爱这个项目的的人最后也会参与到这个项目中来,从使用者到项目的维护者,可以为项目贡献一份自己的力量.我以后也会将维护这个项目的一些 ...

  6. element 往node里面增加属性值_【Vue原理】Compile - 源码版 之 Parse 属性解析

    写文章不容易,点个赞呗兄弟 专注 Vue 源码分享,文章分为白话版和 源码版,白话版助于理解工作原理,源码版助于了解内部详情,让我们一起学习吧 研究基于 Vue版本 [2.5.17] 如果你觉得排版难 ...

  7. element表格里面放图片_Element UI table里上传图片后如何显示在表格里

    问题描述 写了一个后台管理系统,需求是通过新增按钮,弹出一个dialog来上传 图片,详情(文章),视频. 不太明白这整个逻辑怎么实现. 问题出现的环境背景及自己尝试过哪些方法 现在的问题就是我在di ...

  8. 使用element UI 快速制作一个列表页面

    使用element制作一个列表页面,并且当点击"查看调查问卷"时弹出弹框. (图一) (图二) (图三) 1. 制作一个名叫DataListTable <DataListTa ...

  9. vue3.0、cli4项目引入element plus

    element团队为新版的 vue-cli4 准备了相应的 Element Plus 插件 安装依赖 npm install element-plus --save main.js全局引入,样式文件需 ...

最新文章

  1. 精灵图 html为什么会变大,[html] 第128天 精灵图和base64如何选择呢?
  2. 设计模式之迭代器模式java实现代码
  3. .net remoting在wpf中的应用
  4. android studio多页面滑动,Android Studio之多个Activity的滑动切换(二)
  5. 解决问题 “You don't have permission to access /index.html on this server.”
  6. 移动WEB开发之JS内置touch事件[转]
  7. 【英语学习】【Daily English】U15 Culture L03 How will that help me to fit in
  8. 大数据之-Hadoop3.x_MapReduce_HashPartitioner分区---大数据之hadoop3.x工作笔记0111
  9. JavaScript面向对象 - 严格模式
  10. spring教程笔记2
  11. HSC-1th 2022 Writeup
  12. 蓝桥 超级玛丽 JAVA
  13. 判断一个数是否为4的倍数
  14. 数据压缩——LZW 编解码算法实现与分析
  15. MYSQL 查询某个月有多少天数?
  16. 大数据分析 | 用 Python 做文本词频分析
  17. bookkeeper命令行操作
  18. 一份标准的软件测试计划文档 | 新手可以拿走
  19. 使用git 提交本地文件夹及文件
  20. 2020年元旦上海计算机类会议,CARC2020年元旦晚会

热门文章

  1. @Validated和@Valid
  2. 做微商如何快速建立信任?
  3. PCI-DSS安全认证
  4. 2008年世界顶级杀毒软件排行榜
  5. 8*8点阵引脚图 行列定义
  6. 3000字扫盲shell基础知识(新手必备)
  7. 程序员必须知道的9大数据挖掘工具
  8. C语言足球比赛6场,一场激烈的足球赛作文600字
  9. MVP从入门到...
  10. js 保留两位数且不四舍五入