1.基础练习
练习1
<template>
<!--按钮-->
<el-row>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</el-row>
<br>
<!--表格-->
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="日期" width="180">
</el-table-column>
<el-table-column prop="name" label="姓名" width="180">
</el-table-column>
<el-table-column prop="address" label="地址">
</el-table-column>
</el-table>
<!--pagination 分页-->
<div class="block">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4"
:page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
</el-pagination>
<!--dialog 對話框-->
<!-- Table -->
<el-button type="text" @click="dialogTableVisible = true">打开嵌套表格的 Dialog</el-button>
<el-dialog title="收货地址" :visible.sync="dialogTableVisible">
<el-table :data="gridData">
<el-table-column property="date" label="日期" width="150"></el-table-column>
<el-table-column property="name" label="姓名" width="200"></el-table-column>
<el-table-column property="address" label="地址"></el-table-column>
</el-table>
</el-dialog>
</div>
<!--diolog-form表单-->
<el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button>
<el-dialog title="表单" :visible.sync="dialogFormVisible">
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="活动名称">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="活动区域">
<el-select v-model="form.region" placeholder="请选择活动区域">
<el-option label="区域一" value="shanghai"></el-option>
<el-option label="区域二" value="beijing"></el-option>
</el-select>
</el-form-item>
<el-form-item label="活动时间">
<el-col :span="11">
<el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
</el-col>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">提交</el-button>
<el-button>取消</el-button>
</el-form-item>
</el-form>
</el-dialog>
</template>
<script>
export default{
data() {
return {
form: {
name: '',
region: '',
date1: '',
date2: ''
},
gridData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}],
dialogTableVisible: false,
dialogFormVisible: false,
tableData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄'
}],
currentPage4: 4
};
},
methods: {
handleSizeChange: function (val) {
alert("每頁" + val + "條");
},
handleCurrentChange(val) {
alert("當前頁" + val + "條");
},
onSubmit() {
alert(JSON.stringify(this.form));
}
}
}
</script>
<style>
</style>
运行结果
练习二
DeptView.view
<template>
<el-container style="height: 700px; border: 1px solid #eee">
<el-header style="font-size: 40px; background-color:rgb(224, 224, 224)">tlias智能学习辅助系统</el-header>
<el-container>
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu :default-openeds="['1', '3']">
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>信息系统管理</template>
<el-menu-item-group>
<el-menu-item index="1-1">
<router-link to="/dept">部门管理</router-link>
</el-menu-item>
<el-menu-item index="1-2">
<router-link to="/emp">员工管理</router-link>
</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</el-aside>
<el-main>
<!--表格-->
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="name" label="名称" width="180">
</el-table-column>
<el-table-column prop="updatetime" label="最后操作时间" width="180"></el-table-column>
<el-table-column label="操作">
<el-button type="primary" size="mini">编辑</el-button>
<el-button type="danger" size="mini">删除</el-button>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-container>
</template>
<script>
export default{
data() {
return {
tableData: [{
name: '学工部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '教研部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '就业部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '人事部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '行政部',
updatetime: '2010-12-01 12:00:00'
}]
};
}
}
</script>
<style>
</style><template>
<el-container style="height: 700px; border: 1px solid #eee">
<el-header style="font-size: 40px; background-color:rgb(224, 224, 224)">tlias智能学习辅助系统</el-header>
<el-container>
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu :default-openeds="['1', '3']">
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>信息系统管理</template>
<el-menu-item-group>
<el-menu-item index="1-1">
<router-link to="/dept">部门管理</router-link>
</el-menu-item>
<el-menu-item index="1-2">
<router-link to="/emp">员工管理</router-link>
</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</el-aside>
<el-main>
<!--表格-->
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="name" label="名称" width="180">
</el-table-column>
<el-table-column prop="updatetime" label="最后操作时间" width="180"></el-table-column>
<el-table-column label="操作">
<el-button type="primary" size="mini">编辑</el-button>
<el-button type="danger" size="mini">删除</el-button>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-container>
</template>
<script>
export default{
data() {
return {
tableData: [{
name: '学工部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '教研部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '就业部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '人事部',
updatetime: '2010-12-01 12:00:00'
}, {
name: '行政部',
updatetime: '2010-12-01 12:00:00'
}]
};
}
}
</script>
<style>
</style>
EmpView.view
<template>
<el-container style="height: 700px; border: 1px solid #eee">
<el-header style="font-size: 40px; background-color:rgb(224, 224, 224)">tlias智能学习辅助系统</el-header>
<el-container>
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu :default-openeds="['1', '3']">
<el-submenu index="1">
<template slot="title"><i class="el-icon-message"></i>信息系统管理</template>
<el-menu-item-group>
<el-menu-item index="1-1">
<router-link to="/dept">部门管理</router-link>
</el-menu-item>
<el-menu-item index="1-2">
<router-link to="/emp">员工管理</router-link>
</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</el-aside>
<el-main>
<!--表单-->
<el-form :inline="true" :model="formInline" class="demo-form-inline">
<el-form-item label="姓名">
<el-input v-model="formInline.name" placeholder="姓名"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-select v-model="formInline.gender" placeholder="性别">
<el-option label="男" value=""></el-option>
<el-option label="女" value=""></el-option>
</el-select>
</el-form-item>
<el-form-item label="入职时间">
<el-date-picker v-model="formInline.entrydate" type="entrydate" range-separator="至" start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">查询</el-button>
</el-form-item>
</el-form>
<!--表格-->
<el-table :data="tableData" border>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column label="图像" width="180">
<template slot-scope="scope">
<img :src="scope.row.image" width="100px" height="70px">
</template>
</el-table-column>
<el-table-column label="性别" width="140">
<template slot-scope="scope">
{{ scope.row.gender==1? '男' : '女' }}
</template>
</el-table-column>
<el-table-column prop="job" label="职位" width="140"></el-table-column>
<el-table-column prop="entrydate" label="入职日期" width="180"></el-table-column>
<el-table-column prop="updatetime" label="最后操作时间" width="230"></el-table-column>
<el-table-column label="操作">
<el-button type="primary" size="mini">编辑</el-button>
<el-button type="danger" size="mini">删除</el-button>
</el-table-column>
</el-table>
<br>
<!--分页-->
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4"
:page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
</el-pagination>
</el-main>
</el-container>
</el-container>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
tableData: [],
formInline:{
name:"",
gender:"",
entrydate:[]
},
currentPage4: 4
}
},
methods:{
handleSizeChange: function (val) {
alert("每頁" + val + "條");
},
handleCurrentChange(val) {
alert("當前頁" + val + "條");
},
onSubmit() {
alert("查询数据");
}
},
mounted(){
//发送异步请求获取数据
axios.get("https://mock.apifox.cn/m1/3128855-0-default/emp/list").then((result)=>{
this.tableData=result.data.data;
});
}
}
</script>
<style>
.el-header {
background-color: #B3C0D1;
color: #333;
line-height: 60px;
}
.el-aside {
color: #333;
}
</style>
运行结果