一.引入Element按钮,Container布局容器,菜单侧边栏
1.简单回顾vue的安装和创建项目。
2.访问Element官网。 链接:https://element-plus.org/zh-CN/component/button.html 选择红色按钮,
复制红色按钮的代码到vscode的app.vue文件。
1 2 3 4 5 6 7 8 9 10
| <script setup> import { ElButton } from 'element-plus' </script>
<template> <el-button type="info">Danger</el-button> </template>
<style scoped> </style>
|
3.发现红色按钮位置是在正中间,是错误的。后来经过老师的提示,要把main.js文件中下列居中代码删掉。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702477935327-f9d694eb-44fc-46d6-8140-63ab3670947e.png)
1
| import './assets/main.css'
|
4.找到要用到的布局,先查看它的代码,再复制到app.vue。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702477982134-682e8b51-64a8-4a95-9d30-9f950184080b.png)
1 2 3 4 5 6 7 8 9
| <div class="common-layout"> <el-container> <el-aside width="200px">Aside</el-aside> <el-container> <el-header>Header</el-header> <el-main>Main</el-main> </el-container> </el-container> </div>
|
5.找到要用到的菜单侧边栏,先查看它的代码,再复制到app.vue。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702478014643-2c19b422-9987-4c66-a26b-05ed460f4661.png)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <template> <el-row class="tac"> <el-col :span="12"> <h5 class="mb-2">Default colors</h5> <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" > <el-menu-item index="2"> <el-icon><icon-menu /></el-icon> <span>Navigator Two</span> </el-menu-item> <el-menu-item index="3" disabled> <el-icon><document /></el-icon> <span>Navigator Three</span> </el-menu-item> <el-menu-item index="4"> <el-icon><setting /></el-icon> <span>Navigator Four</span> </el-menu-item> </el-menu> </el-col> <el-col :span="12"> <h5 class="mb-2">Custom colors</h5> <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" default-active="2" text-color="#fff" @open="handleOpen" @close="handleClose" > <el-sub-menu index="1"> <template #title> <el-icon><location /></el-icon> <span>Navigator One</span> </template> <el-menu-item-group title="Group One"> <el-menu-item index="1-1">item one</el-menu-item> <el-menu-item index="1-2">item two</el-menu-item> </el-menu-item-group> <el-menu-item-group title="Group Two"> <el-menu-item index="1-3">item three</el-menu-item> </el-menu-item-group> <el-sub-menu index="1-4"> <template #title>item four</template> <el-menu-item index="1-4-1">item one</el-menu-item> </el-sub-menu> </el-sub-menu> <el-menu-item index="2"> <el-icon><icon-menu /></el-icon> <span>Navigator Two</span> </el-menu-item> <el-menu-item index="3" disabled> <el-icon><document /></el-icon> <span>Navigator Three</span> </el-menu-item> <el-menu-item index="4"> <el-icon><setting /></el-icon> <span>Navigator Four</span> </el-menu-item> </el-menu> </el-col> </el-row> </template>
<script lang="ts" setup> import { Document, Menu as IconMenu, Location, Setting, } from '@element-plus/icons-vue' const handleOpen = (key: string, keyPath: string[]) => { console.log(key, keyPath) } const handleClose = (key: string, keyPath: string[]) => { console.log(key, keyPath) } </script>
|
6.在app.vue中删除下列代码的string
1 2 3 4 5 6
| const handleOpen = (key: string, keyPath: string[]) => { console.log(key, keyPath) } const handleClose = (key: string, keyPath: string[]) => { console.log(key, keyPath) }
|
7.把span=12改成span=24,侧边栏span=24表示占满 el-col :span=”24”表示竖直方向占满
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702298169039-6bf73205-5c61-4b50-b56b-518fa680bfea.png)
8.在侧边栏导入图标,复制代码在对应的用户管理,权限管理,商品管理,订单管理语句各自的前一行。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702478133938-4a3a0f16-2685-47d7-b5fc-2fa4e3f3f26c.png)
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702298662954-37b0eb22-a73f-4b8f-badd-6a21f1a55a4b.png)
1.在el-header中创建styled-box1类。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702299037715-c342f095-d463-419a-98bf-1b325dcfdd94.png)
在style创建styled-box1样式。
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702299210651-716ae9ad-d358-4049-82fe-ba1e0fdf90f0.png)
2.CTRL+S保存,在终端输入npm run dev, 结果如下图
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702299408016-718c337f-2f6d-4c53-8f5f-db3ee347fe6f.png)
3.引入搜索框input和搜索,添加用户两个按钮,注意el-row是行,el-col是列。
1 2 3 4 5 6 7
| <el-row> <el-col :span="4" ><el-input v-model="input" placeholder="请输入搜索内容" /></el-col> <el-col :span="2"><el-button type="success">搜索</el-button></el-col> <el-col :span="2"> <el-button type="success">添加用户</el-button></el-col> </el-row>
|
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702300021651-558624ba-d852-43da-aa59-4fad9e072223.png)
三.引入表格和分页
1.找到表格,复制代码引入app.vue
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702478209116-41c089fd-0661-4edf-a77a-0c4c56681425.png)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <template> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="date" label="Date" width="180" /> <el-table-column prop="name" label="Name" width="180" /> <el-table-column prop="address" label="Address" /> </el-table> </template>
<script lang="ts" setup> const tableData = [ { date: '2016-05-03', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-02', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-04', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, { date: '2016-05-01', name: 'Tom', address: 'No. 189, Grove St, Los Angeles', }, ] </script>
|
2.找到分页,引入分页
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702478241936-99f04e0f-0a46-45ea-8cec-2849c886f97f.png)
1 2 3 4 5 6 7 8
| <template> <el-pagination :page-size="20" :pager-count="11" layout="prev, pager, next" :total="1000" /> </template>
|
刷新浏览器页面,最终的页面如下:
![image.png](https://raw.githubusercontent.com/Xiaotang23/tu/main/img/1702478272976-d56c923e-07ad-4c65-a0c9-0ca9a971be3a.png)