Vue2集成ElementUI

软件版本

1.jdk 1.8
2.mysql5.7+
3.node14.16.0
4.navicat
5.idea2021.3
检查一下这些插件是否已安装:
在这里插入图片描述
Vue官网文档地址链接: https://v2.cn.vuejs.org/v2/guide
Vue cli安装命令如下:

npm install -g @vue/cli

创建一个项目

1.运行以下命令来创建一个叫vue01的新项目

vue create vue01

按回车
在这里插入图片描述
按箭头

在这里插入图片描述
按空格选择
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
项目正在创建中···(npm设置一个镜像加速会下载的快一点)
在这里插入图片描述

项目创建成功
在这里插入图片描述
vue的工程目录如下:
在这里插入图片描述
我用的是idea打开的这个项目 打开之后的界面如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/c5816c3fe67847c59857d47fe6d63398.png
启动此项目
在这里插入图片描述
在浏览器中输入端口 回车
在这里插入图片描述
自己试试能不能用
在这里插入图片描述
刷新一下 诶 能用 万事大吉
在这里插入图片描述
Element UI官网链接: https://element.eleme.cn/#/zh-CN/component/installation
按crtl+C终止控制台
在这里插入图片描述
idea控制台运行element ui插件

npm i element-ui -S

在这里插入图片描述
在package.json中发现element ui插件已经下载完成
在这里插入图片描述
在main.js中引入这几行代码实验一下这个插件是否可用
在这里插入图片描述

import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
Vue.use(ElementUI);

在这里插入图片描述
在控制台启动一下项目
在这里插入图片描述
测试成功
在这里插入图片描述
恭喜你,至此项目已经创建成功!

Vue后台主体框架的搭建(类似Element官网的布局)

1.home.vue

<template>
  <el-container style="height: 100%;">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246);height: 100%; box-shadow: 2px 0 6px rgb(0 21 41)">
      <el-menu :default-openeds="['1', '3']" style="min-height: 100%;overflow-x: hidden"
               background-color="rgb(48, 65, 86)" text-color="#fff" active-text-color="#ffd04b" :collapse-transition="false" :collapse="isCollapse">
               <!--头部菜单-->
        <div style="height: 60px;line-height: 60px;text-align: center">
          <img src="../assets/logo.png" alt="" style="width: 20px;position: relative;top: 5px;margin-right: 5px">
          <b style="color: white" v-show="LogoTextShow">餐饮管理系统</b>
        </div>
        <el-submenu index="1">
          <template slot="title"><i class="el-icon-message"></i>导航一</template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="1-1">选项1</el-menu-item>
            <el-menu-item index="1-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="1-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title"><i class="el-icon-menu"></i>导航二</template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="2-1">选项1</el-menu-item>
            <el-menu-item index="2-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="2-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="2-4">
            <template slot="title">选项4</template>
            <el-menu-item index="2-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title"><i class="el-icon-setting"></i>导航三</template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="3-1">选项1</el-menu-item>
            <el-menu-item index="3-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="3-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="3-4">
            <template slot="title">选项4</template>
            <el-menu-item index="3-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px;border-bottom:1px solid #ccc;line-height:60px ">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>查看</el-dropdown-item>
            <el-dropdown-item>新增</el-dropdown-item>
            <el-dropdown-item>删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>王小虎</span>
      </el-header>

      <el-main>
        <el-table :data="tableData">
          <el-table-column prop="date" label="日期" width="140">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="120">
          </el-table-column>
          <el-table-column prop="address" label="地址">
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
  </el-container>
  <!--<div class="home">
    <h1>{{msg}}</h1>
    <el-button>这是一个测试按钮</el-button>
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>-->
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'Home',
  data(){
    const item = {
      date: '2016-05-02',
      name: '王小虎',
      address: '上海市普陀区金沙江路 1518 弄'
    };
    return{
      tableData: Array(10).fill(item),
      msg:"hello 美女",
      collapseBtnClass:'el-icon-s-fold',
      isCollapse:false,
      sideWidth:200,
      LogoTextShow:true
    }
  },
  methods:{
    collapse(){//点击收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse){ //收缩
        this.sideWidth = 64
        this.collapseBtnClass = "el-icon-s-unfold"
        this.LogoTextShow = false
      }else{ //展开
        this.sideWidth = 200
        this.collapseBtnClass = "el-icon-s-fold"
        this.LogoTextShow = true
      }
    }
  }
}
</script>

创建globel.css
在这里插入图片描述
globel.css

html,body,div{
    margin: 0;
    padding: 0;
}
html,body{
    height: 100%;
}

高度撑满
在这里插入图片描述
App.vue

<template>
  <div id="app">
    <router-view/>
  </div>
</template>
<style>
  #app{
    height: 100%;
  }
</style>


Home.vue修改

<template>
  <div style="height: 100%">
  <el-container style="height: 100%;">
    <el-aside :width="sideWidth + 'px'" style="background-color: rgb(238, 241, 246);height: 100% ; box-shadow: 2px 0 6px rgb(0 21 41)">
      <el-menu :default-openeds="['1', '3']" style="min-height: 100vh;overflow-x: hidden"
               background-color="rgb(48, 65, 86)"
               text-color="#fff"
               active-text-color="#ffd04b"
               :collapse-transition="false"
               :collapse="isCollapse">
        <!--头部菜单-->
        <div style="height: 60px;line-height: 60px;text-align: center">
          <img src="../assets/logo.png" alt="" style="width: 20px;position: relative;top: 5px;margin-right: 5px">
          <b style="color: white" v-show="LogoTextShow">餐饮管理系统</b>
        </div>
        <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-message"></i>
            <span slot="title">导航一</span>
          </template>
          <el-menu-item-group title="分组2">
            <el-menu-item index="1-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span slot="title">导航二</span>
          </template>
          <el-submenu index="2-4">
            <template slot="title">选项4</template>
            <el-menu-item index="2-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-setting"></i>
            <span slot="title">导航三</span>
          </template>
          <el-submenu index="3-4">
            <template slot="title">选项4</template>
            <el-menu-item index="3-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="font-size: 12px ;border-bottom:1px solid #ccc;line-height:60px;display: flex ">
        <!--收缩按钮-->
        <div style="flex: 1;font-size: 18px">
          <span :class="collapseBtnClass" style="curson:pointer" @click="collapse"></span>
        </div>
        <el-dropdown style="width: 70px;cursor:pointer">
          <span>王小虎</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人信息</el-dropdown-item>
            <el-dropdown-item>退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>

      <el-main>
        <!--el-icon-message 邮箱-->
        <div style="padding: 10px 0">
          <el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search"></el-input>
          <el-input style="width: 200px" placeholder="请输入邮箱" suffix-icon="el-icon-edit" class="ml-5"></el-input>
          <el-input style="width: 200px" placeholder="请输入地址" suffix-icon="el-icon-position" class="ml-5"></el-input>
          <el-button class="ml-5" type="primary">搜索</el-button>
        </div>
        <div style="margin: 10px 0">
          <el-button type="primary">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
          <el-button type="danger">批量删除 <i class="el-icon-remove-outline"></i></el-button>
          <el-button type="primary">导入 <i class="el-icon-bottom"></i></el-button>
          <el-button type="primary">导出 <i class="el-icon-top"></i></el-button>
        </div>
        <el-table :data="tableData" border stripe :header-cell-class-name="headerBg">
          <el-table-column prop="date" label="日期" width="140">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="120">
          </el-table-column>
          <el-table-column prop="address" label="地址">
          </el-table-column>
          <el-table-column  label="操作">
            <template slot-scope="scope">
              <el-button type="success">编辑<i class="el-icon-edit"></i></el-button>
              <el-button type="danger">删除<i class="el-icon-remove-outline"></i></el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="padding: 10px 0">
          <el-pagination
                  :page-sizes="[5, 10, 15, 20]"
                  :page-size="10"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="400">
          </el-pagination>
        </div>
      </el-main>
    </el-container>
  </el-container>
  <!--<div class="home">
    <h1>{{msg}}</h1>
    <el-button>这是一个测试按钮</el-button>
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>-->
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'Home',
  data(){
    const item = {
      date: '2016-05-02',
      name: '王小虎',
      address: '上海市普陀区金沙江路 1518 弄'
    };
    return{
      tableData: Array(10).fill(item),
      msg:"hello 美女",
      collapseBtnClass:'el-icon-s-fold',
      isCollapse:false,
      sideWidth:200,
      LogoTextShow:true,
      headerBg:'headerBg'
    }
  },
  methods:{
    collapse(){//点击收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse){ //收缩
        this.sideWidth = 64
        this.collapseBtnClass = "el-icon-s-unfold"
        this.LogoTextShow = false
      }else{ //展开
        this.sideWidth = 200
        this.collapseBtnClass = "el-icon-s-fold"
        this.LogoTextShow = true
      }
    }
  }
}
</script>
<style>
  .headerBg{
    background: #eee !important;
  }
</style>

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值