iis服务器助手广告广告
返回顶部
首页 > 资讯 > 操作系统 >Vue2项目练手——通用后台管理项目第一节
  • 938
分享到

Vue2项目练手——通用后台管理项目第一节

前端javascriptvue.js 2023-08-30 15:08:26 938人浏览 泡泡鱼
摘要

Vue2项目练手——通用后台管理项目 知识补充yarn和npm区别npm的缺点:yarn的优点 npm查看镜像和设置镜像 项目介绍项目的技术栈 项目搭建文件目录 创建路由,引入element-uirouter/in

知识补充

yarn和npm区别

npm的缺点:

  1. npm install时候巨慢
  2. 同一个项目,安装的时候无法保持一致性。 由于package.JSON文件中版本号的特点。

“5.0.3” 安装指定的5.0.3版本
“~5.0.3” 表示安装5.0.X中最新的版本
“^5.0.3” 表示安装5.X.X中最新的版本

有时候会出现版本不一致不能运行的情况。

yarn的优点

  1. 速度快
    并行安装:同步执行所有任务,不像npm按照队列执行每个package,package安装不完成,后面也无法执行。
    离线模式:安装过得软件包,直接从缓存中获取,不用像npm从网络中获取。
  2. 安装版本统一
  3. 更简洁的输出:
    npm输出所有被安装上的依赖,但是yarn只打印必要的信息
  4. 多注册来源处理:安装某个包,只会从一个注册来源去安装,
  5. 更好的语义化,yarn安装和卸载是yarn add/remove,npm是npm install/uninstall

npm查看镜像和设置镜像

npm config get reGIStry
npm config set registry https://registry.npmmirror.com/

项目介绍

项目的技术栈

在这里插入图片描述

  1. 使用yarn安装vue-cli

yarn global add @vue/cli

项目搭建

先vue create创建一个项目,然后安装element-ui组件和vue-router,less等组件

文件目录

请添加图片描述

创建路由,引入element-ui

router/index.js

import VueRouter from "vue-router";import Login from "@/pages/Login.vue";import Users from "@/pages/Users.vue";import Main from '@/pages/Main.vue'import Home from "@/pages/Home.vue";const router= new VueRouter({    // 浏览器模式设置,设置为history模式    mode:'history',    routes:[        {            path:"/login",            component:Login,            meta:{title:"登录"},        },        {            // 主路由            name:"main",            path:'/',            component:Main,            children:[  //子路由                {                    name:"users",                    path:"users",                    component:Users,                    meta:{title:"用户"}                },                {                    name:"home",                    path:"home",                    component:Home,                    meta:{title:"主页"}                }            ]        }    ]})// 后置路由守卫router.afterEach((to,from)=>{    document.title=to.meta.title||"通用后台管理系统"})export default router

main.js

import Vue from 'vue'import App from './App.vue'import VueRouter from "vue-router";import router from "@/router";import ElementUI from 'element-ui';import 'element-ui/lib/theme-chalk/index.CSS'Vue.config.productionTip = falseVue.use(VueRouter)Vue.use(ElementUI)new Vue({  router,  render: h => h(App),}).$mount('#app')

pages/Users.vue

<template>  <div>    我是Users组件  div>template><script>export default {  name: "Users",}script><style scoped>style>

pages/Main.vue

<template>  <div>    <h1>mainh1>    <router-view>router-view>  div>template><script>export default {  name: "Main",}script><style scoped>style>

pages/Home.vue

<template>  <div>    home内容  div>template><script>export default {  name: "Home",}script><style scoped>style>

pages/Login.vue

<template>  <div id="app">    <div class="main-content">      <div class="title">系统登录div>      <div class="content">        <el-fORM :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">          <el-form-item label="用户名" prop="name">            <el-input v-model="ruleForm.name" >el-input>          el-form-item>          <el-form-item label="密码" prop="passWord">            <el-input v-model="ruleForm.password" type="password" autocomplete="off">el-input>          el-form-item>          <el-form-item>            <el-row :gutter="20">              <el-col :span="12" :offset="4"><router-link to="/login"><el-button type="primary" @click="submitForm('ruleForm')">登录el-button>router-link>el-col>            el-row>          el-form-item>        el-form>      div>    div>  div>template><script>export default {  name: "login",  data(){    return{      ruleForm: {        name: '',        password:""      },      rules: {        name: [          {required: true, message: '请输入用户名', trigger: 'blur'},          {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}        ],        password: [          {required:true,message:"请输入密码",trigger:"blur"}        ]      }    }  },  methods:{    submitForm(formName) {      this.$refs[formName].validate((valid) => {        if (valid) {          // alert('submit!');        } else {          console.log('error submit!!');          return false;        }      });    },  }}script><style lang="less" scoped>*{  padding: 0;  margin: 0;}#app {  display: flex;  background-color: #333;  height: 800px;  .main-content{    height: 300px;    width: 400px;    background-color: #fff;    margin: 200px auto;    border-radius: 10px;    padding: 30px;    box-sizing: border-box;    box-shadow: 5px  5px 10px rgba(0,0,0,0.5),-5px -5px 10px rgba(0,0,0,0.5);    .title{      font-size: 20px;      text-align: center;      //margin-top: 30px;      font-weight: 300;    }    .content{      margin-top: 30px;    }  }}style>

App.vue

<template>  <div id="app">    <router-view>router-view>  div>template><script>export default {  name: 'App',}script><style lang="less">*{  padding: 0;  margin: 0;}style>

请添加图片描述

使用element-ui搭建主页样式

main页面布局使用这个

请添加图片描述
请添加图片描述

Main.vue

<template>  <div>    <el-container>      <el-aside width="200px">Asideel-aside>      <el-container>        <el-header>Headerel-header>        <el-main>          <router-view>router-view>        el-main>      el-container>    el-container>  div>template><script>export default {  name: "Main",}script><style scoped>style>

请添加图片描述

导航栏使用

请添加图片描述

导航栏适配

Main.vue

<template>  <div>    <el-container>      <el-aside width="200px">        <CommonAside>CommonAside>      el-aside>      <el-container>        <el-header>Headerel-header>        <el-main>          <router-view>router-view>        el-main>      el-container>    el-container>  div>template><script>import CommonAside from "@/components/CommonAside.vue";export default {  name: "Main",  components:{CommonAside}}script><style scoped>style>

App.vue

<template>  <div id="app">    <router-view>router-view>  div>template><script>export default {  name: 'App',}script><style lang="less">html,body,h3{  padding: 0;  margin: 0;}style>

CommonAside

<template>    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"             :collapse="isCollapse" background-color="#545c64" text-color="#fff"             active-text-color="#ffd04b">      <h3>通用后台管理系统h3>      <el-menu-item index="2" v-for="item in noChildren" :key="item.name" :index="item.name">        <i :class="`el-icon-${item.icon}`">i>        <span slot="title">{{item.label}}span>      el-menu-item>      <el-submenu :index="item.label" v-for="item in hasChildren" :key="item.label">        <template slot="title">          <i :class="`el-icon-${item.icon}`">i>          <span slot="title">{{item.label}}span>        template>        <el-menu-item-group>          <el-menu-item :index="subItem.path" :key="subItem.path" v-for="subItem in item.children">            {{subItem.label}}          el-menu-item>        el-menu-item-group>      el-submenu>    el-menu>template><style lang="less" scoped>.el-menu-vertical-demo:not(.el-menu--collapse) {  width: 200px;  min-height: 400px;}.el-menu{  height: 100vh;  //占据页面高度100%  h3{    color: #fff;    text-align: center;    line-height: 48px;    font-size: 16px;    font-weight: 400;  }}style><script>export default {  data() {    return {      isCollapse: false,      menuData:[        {          path:'/',          name:"home",          label:"首页",          icon:"s-home",          url:'Home/Home'        },        {          path:'/mail',          name:"mall",          label:"商品管理",          icon:"video-play",          url:'MallManage/MallManage'        },        {          path:'/user',          name:"user",          label:"用户管理",          icon:"user",          url:'userManage/userManage'        },        {          label:"其他",          icon:"location",          children:[            {              path:'/page1',              name:"page1",              label:"页面1",              icon:"setting",              url:'Other/PageOne'            },            {              path:'/page2',              name:"page2",              label:"页面2",              icon:"setting",              url:'Other/PageTwo'            },          ]        },      ]    };  },  methods: {    handleOpen(key, keyPath) {      console.log(key, keyPath);    },    handleClose(key, keyPath) {      console.log(key, keyPath);    }  },  computed:{    //没有子菜单的数据    noChildren(){      return this.menuData.filter(item=>!item.children)    },    hasChildren(){      return this.menuData.filter(item=>item.children)    }    //有子菜单数组  }}script>

请添加图片描述

导航栏跳转

文件目录

请添加图片描述

src/router/index.js

import VueRouter from "vue-router";import Login from "@/pages/Login.vue";import Users from "@/pages/Users.vue";import Main from '@/pages/Main.vue'import Home from "@/pages/Home.vue";import Mall from "@/pages/Mall.vue";import PageOne from "@/pages/PageOne.vue";import PageTwo from "@/pages/PageTwo.vue";const router= new VueRouter({    // 浏览器模式设置,设置为history模式    // mode:'history',    routes:[        {            path:"/login",            component:Login,            meta:{title:"登录"},        },        {            // 子路由            name:"main",            path:'/',            redirect:"/home",  //重定向 当路径为/,则重定向home            component:Main,            children:[                {                    name:"user",                    path:"user",                    component:Users,                    meta:{title:"用户管理"}                },                {                    name:"home",                    path:"home",                    component:Home,                    meta:{title:"首页"}                },                {                    name:"mall",                    path:"mall",                    component:Mall,                    meta:{title:"商品管理"}                },                {                    name:"page1",                    path:"page1",                    component:PageOne,                    meta:{title:"页面1"}                },                {                    name:"page2",                    path:"page2",                    component:PageTwo,                    meta:{title:"页面2"}                }            ]        }    ]})// 后置路由守卫router.afterEach((to,from)=>{    document.title=to.meta.title||"通用后台管理系统"})export default router

src/pages/Mall.vue

<template>  <div>    我是mall  div>template><script>export default {  name: "Mall",}script><style scoped>style>

src/pages/pageOne.vue

<template>  <div>    我是PageOne  div>template><script>export default {  name: "PageOne",}script><style scoped>style>

src/pages/PageTwo.vue

<template>  <div>    我是PageTwo  div>template><script>export default {  name: "PageTwo",}script><style scoped>style>

src/components/CommonAside.vue

<template>    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"             :collapse="isCollapse" background-color="#545c64" text-color="#fff"             active-text-color="#ffd04b">      <h3>通用后台管理系统h3>      <el-menu-item @click="clickMenu(item)"  v-for="item in noChildren" :key="item.name" :index="item.name">        <i :class="`el-icon-${item.icon}`">i>        <span slot="title">{{item.label}}span>      el-menu-item>      <el-submenu :index="item.label" v-for="item in hasChildren" :key="item.label">        <template slot="title">          <i :class="`el-icon-${item.icon}`">i>          <span slot="title">{{item.label}}span>        template>        <el-menu-item-group>          <el-menu-item @click="clickMenu(subItem)" :index="subItem.path" :key="subItem.path" v-for="subItem in item.children">            {{subItem.label}}          el-menu-item>        el-menu-item-group>      el-submenu>    el-menu>template><style lang="less" scoped>.el-menu-vertical-demo:not(.el-menu--collapse) {  width: 200px;  min-height: 400px;}.el-menu{  height: 100vh;  //占据页面高度100%  h3{    color: #fff;    text-align: center;    line-height: 48px;    font-size: 16px;    font-weight: 400;  }}style><script>export default {  data() {    return {      isCollapse: false,      menuData:[        {          path:'/',          name:"home",          label:"首页",          icon:"s-home",          url:'Home/Home'        },        {          path:'/mall',          name:"mall",          label:"商品管理",          icon:"video-play",          url:'MallManage/MallManage'        },        {          path:'/user',          name:"user",          label:"用户管理",          icon:"user",          url:'userManage/userManage'        },        {          label:"其他",          icon:"location",          children:[            {              path:'/page1',              name:"page1",              label:"页面1",              icon:"setting",              url:'Other/PageOne'            },            {              path:'/page2',              name:"page2",              label:"页面2",              icon:"setting",              url:'Other/PageTwo'            },          ]        },      ]    };  },  methods: {    handleOpen(key, keyPath) {      console.log(key, keyPath);    },    handleClose(key, keyPath) {      console.log(key, keyPath);    },    clickMenu(item){      // console.log(item)      this.$router.push(item.path)    }  },  computed:{    //没有子菜单的数据    noChildren(){      return this.menuData.filter(item=>!item.children)    },    //有子菜单数组    hasChildren(){      return this.menuData.filter(item=>item.children)    }  }}script>

请添加图片描述

来源地址:https://blog.csdn.net/qq_34306228/article/details/132458711

--结束END--

本文标题: Vue2项目练手——通用后台管理项目第一节

本文链接: https://www.lsjlt.com/news/383147.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Vue2项目练手——通用后台管理项目第一节
    Vue2项目练手——通用后台管理项目 知识补充yarn和npm区别npm的缺点:yarn的优点 npm查看镜像和设置镜像 项目介绍项目的技术栈 项目搭建文件目录 创建路由,引入element-uirouter/in...
    99+
    2023-08-30
    前端 javascript vue.js
  • Java练手小项目实现一个项目管理系统
    目录前言:一、项目需求二、功能实现三、具体模块的实现四、总结前言: 时隔多日,我们学习完java的面向对象阶段,毕竟需要付诸实践,这个小项目就 作为我们第一个java面向对象解决的项...
    99+
    2024-04-02
  • 超适合练手的一套JavaWeb项目 (超市后台管理系统)
    GIF动态图演示 百度百度网盘提取项目 带数据库![链接]:https://pan.baidu.com/s/13F2rxszZRLGDt9pr6ixYUg提取码:关注私信我发送! 一、项目搭建准备工作 1.搭建一个maven web项目2...
    99+
    2023-08-30
    android 前端 后端
  • springboot+vue制作后台管理系统项目
    目录一、所使用的环境配置:二、项目简介三、知识点总结(代码和配置)SpringBoot: 1.Mybatis-Plus配置文件,实现分页查询:MybatisPlusConfig 2....
    99+
    2024-04-02
  • 钉钉中第三方应用 项目管理
    制定计划 第三方应用项目管理需要有一个完整的计划,包括项目的目标、时间表、资源分配等。在制定计划时,需要考虑项目的重要性、紧急程度、实施方案等因素,以便能够有效地管理项目。 分配任务 第三方应用项目管理需要分配任务,以确保项目按照...
    99+
    2023-10-28
    第三方 项目管理 钉钉中
  • Vue3后台管理系统之创建和配置项目
    目录1.概述2.创建项目2.1.创建Vue32.2.手动配置插件2.3.选择hash路由2.4.选择代码校验规范3.项目结构配置3.1.创建配置文件3.2.启动项目3.3.配置ESL...
    99+
    2024-04-02
  • 开源项目学习:若依RuoYi-Vue后台管理系统【基于ruoyi-vue开发新项目】
    开源项目学习-文章目录 第一章 环境搭建 第二章 项目运行 第三章 阅读源码:例子-新增用户接口 第四章 基于ruoyi-vue开发新项目 文章目录 开源项目学习-文章目录前言一、数据库表设...
    99+
    2023-09-29
    vue.js 学习 mysql
  • Vue3管理后台项目使用高德地图选点的实现
    目录前言获取地图Key引入地图 JSAPI初始化地图地图选点组件化使用拓展前言 最近在做的管理后台项目中有一个业务场景是添加门店的地址和经纬度,地址可以输入,但经纬度这样处理却不合适...
    99+
    2024-04-02
  • 【Python项目实战】京东自动抢茅台脚本,此项目不可商用,仅为Python练手使用!
    目前,在多家电商平台都可以抢购茅台酒,包括天猫超市、京东、天猫会员店、国美、苏宁、网易严选等渠道,消费者使用一台手机便可参与抢购,不过,很多消费者依旧不清楚用手机抢茅台怎么抢,因为抢购的人实在太多,需...
    99+
    2023-10-01
    github
  • 钉钉酷应用项目管理怎么开通
    那么,为什么会出现这些问题呢?这些问题的解决方法有哪些呢?下面我们将分别从技术和管理两个方面来介绍如何开通钉钉酷应用项目管理。 一、技术方面的开通 登录 在使用钉钉酷应用项目管理时,必须通过用户名和密码来登录系统。如果用户名和密码错误...
    99+
    2023-10-28
    项目管理 钉钉酷
  • Vue中后台管理类项目兼容IE9+的示例分析
    小编给大家分享一下Vue中后台管理类项目兼容IE9+的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!目前后台管理系统前端...
    99+
    2024-04-02
  • 从零到高手:使用 PHP Git 管理项目
    Git 是一个分布式版本控制系统,对于管理 PHP 项目至关重要。本文将从基础知识到高级技巧,逐步指导您使用 Git。 基础知识 安装 Git: 在计算机上安装 Git,并配置用户名和电子邮件地址。 初始化仓库: 使用 git init...
    99+
    2024-04-02
  • Java 实战练手项目之酒店管理系统的实现流程
    一、项目简述 功能包括(管理员和用户角色): 酒店预订,酒店管理,员工管理,入住原理,订单管理, 楼层管理,退房管理,营业额报表等等。 二、项目运行 环境配置: Jdk1.8 + T...
    99+
    2024-04-02
  • 微信开发准备第一步 Maven仓库管理新建WEB项目
    在我们的项目开发中经常会遇到项目周期很长,项目依赖jar包特别多的情况,所以我们经常会在项目中引入Maven插件,建立起Maven项目,今天我就记录一个简单的Maven项目建立的简单流程!(一)Maven基础项目的建立(前提:你的开发工具中...
    99+
    2023-05-31
    maven web
  • Java 实战练手项目之校园超市管理系统的实现流程
    前端模板框架为Bootstrap,系统分为前台和后台。后台主要为管理员角色,功能有:商品类型管理、商品管理、订单管理、会员管理、管理员管理等。前台用户功能有:登录、注册、查看商品、加...
    99+
    2024-04-02
  • vue后台系统管理项目之角色权限分配管理功能(示例详解)
    目录角色权限分配管理功能role.vue模块1.查询重置搜索2.table列表3.分页4.新建/编辑角色弹窗5.接口引入6.data定义7.methods方法8.created加载角...
    99+
    2024-04-02
  • 小区后台管理系统项目前端html页面模板实现示例
    目录登录小区管理系统主页小区管理菜单房产管理菜单业主信息管理菜单停车位管理菜单服务管理菜单资产管理菜单收费管理菜单管理员管理菜单系统设置项目结构:主要代码展示:登录小区列表登录 小...
    99+
    2024-04-02
  • 使用SpringBoot项目实现一个本地事务管理功能
    使用SpringBoot项目实现一个本地事务管理功能?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。 SpringBoot 事务一直在用 SpringBoot 中的 @Trans...
    99+
    2023-06-06
  • Vue项目新一代状态管理工具Pinia的使用教程
    目录前言Pinia与Vuex的区别使用Pinia直接修改数据的两种方式使用actions修改数据重置state中数据Pinia持久化存储Pinia模块化实现Pinia中store之间...
    99+
    2022-11-13
    vue pinia状态管理工具 vue pinia用法 vue状态管理工具
  • 面试高手必备:如何用Git管理Java项目中的日志输出?
    在Java项目中,日志输出是非常重要的一部分。在调试和开发过程中,我们经常需要查看日志输出来定位问题。同时,对于线上部署的应用,日志输出也是非常重要的一部分,可以帮助我们及时发现并解决问题。而Git是目前最流行的版本控制工具之一,如何在G...
    99+
    2023-08-07
    面试 日志 git
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作