Element-UI
Element-UI
安装
1 |
# 在 vue 项目中启动终端执行 |
-
按需加载
按需加载
基础使用
-
引入
1
2
3
4
5
6
7
8
9
10
11
12
13
14<!-- Button.vue -->
<template>
<div>
<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>
<router-view />
</div>
</template>-
渲染
Button
使用 -
属性介绍: 使用
type
、plain
、round
和 circle
属性来定义 Button 的样式。 -
灵活使用属性即可获得想要的结果
-
Layout
布局
-
通过基础的
24
分栏,迅速简便地创建布局。 -
offset
属性使用 offset
RadioButton
-
使用
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<template>
<div class="radio-button">
<template>
<el-radio v-model="label" label="男">男 </el-radio>
<el-radio v-model="label" label="女">女 </el-radio>
</template>
<router-view />
</div>
</template>
<script>
export default ({
data(){
return{
label:'男'
}
}
})
</script>
<style scoped>
.radio-button{
margin: 50px;
}
</style> -
渲染
radio-button
使用需要与 v-model
共同配合
Input
input |
---|
![]() |
- 在使用组件的方法时需要在对应的组件中加入
ref="组件别名"
- 在调用方法时直接使用
this.$refs.
组件别名. 方法名 () - 在
element-ui
中所有组件标签上, 使用方式 属性名
方式= 属性值 属性
: 直接写在对应的组件标签上,使用方式 属性名
方式= 属性值 事件
: 直接使用vue
绑定事件方式写在对应的组件标签上, 使用方式 @
事件名 =vue 中事件的处理函数
Select
1 |
<template> |
Switch 开关组件
-
使用
-
后台传值为
boolean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22<template>
<div class="div">
<el-switch
v-model="value"
<!-- name 数据库操作 -->
name="switch"
active-color="#13ce66"
inactive-color="#ff4949">
</el-switch>
<router-view></router-view>
</div>
</template>
<script>
export default {
data() {
return {
value: true
}
}
};
</script> -
后台传值为
number
1
2
3
4
5
6
7
8
9
10
11
12
13
14<template slot-scope='scope'>
<el-tooltip class='item'
effect='dark'
:content='scope.row.status=="1"?"正常":"禁用"'
placement='top-start'
:enterable='false'>
<el-switch
v-model='scope.row.status'
inactive-color='#ff4949'
:active-value='1'
:inactive-value='0'>
</el-switch>
</el-tooltip>
</template>-
渲染效果
switch
-
-
DatePicker 组件使用
1 |
<template> |
-
渲染
渲染
Select
-
基础使用
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<el-select v-model="value" placeholder="请选择">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<script>
export default {
data() {
return {
options: [{
value: '选项1',
label: '黄金糕'
}, {
value: '选项2',
label: '双皮奶'
}, {
value: '选项3',
label: '蚵仔煎'
}, {
value: '选项4',
label: '龙须面'
}, {
value: '选项5',
label: '北京烤鸭'
}],
value: ''
}
}
}
</script> -
数值使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18options: [{
value: '1',
label: '1'
}, {
value: '2',
label: '2'
}, {
value: '3',
label: '3'
}, {
value: '4',
label: '4'
}, {
value: '5',
label: '5'
}]也可以使用修饰符 v-model.number="xxx" -
渲染
数值使用
-
Message
-
使用一
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<template>
<div class="message-view">
<el-button :plain="true" @click="getMessage" type="success">打开消息提示 </el-button>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: "MessageView",
methods: {
getMessage() {
this.$message({
showClose: true,
message: '恭喜你,这是一条成功消息',
type: 'success',
offset: 50,
duration: 1000
});
}
}
}
</script>
<style scoped>
.message-view {
margin: 50px;
}
</style>-
渲染
渲染
-
-
使用二
1
2
3
4// Message 需要全局挂载 plugin/element.js
Vue.prototype.$message = Message
this.$message.success('成功获取点击后的提示信息!');
MessageBox
-
全局挂载
1
2
3// 不需要经过 Vue.use()
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$message = Message -
使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17handleDelete(id) {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
} -
渲染
MessageBox
Select
-
效果
下拉框数据绑定 -
实现分析
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15<el-select v-model='dishCategoryList' placeholder='请选择菜品分类'>
<el-option
v-for='item in formFoodInput.category'
:key='item.id'
:label='item.name'
:value='item.name'
>
</el-option>
</el-select>
dishCategoryList: '' <!-- 选择后的数据绑定 -->
formFoodInput.category: [] <!-- 获取数据绑定 -->1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18/**
* 获取下拉分类请求
*
* @param category
* @return
*/
public R<List<Category>> list(Category category) {
log.info("根据条件查询分类: {}", category.toString());
/* 条件构造器 */
LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
/* 添加条件 */
queryWrapper.eq(category.getType() != null, Category::getType, category.getType());
/* 添加排序条件 */
queryWrapper.orderByAsc(Category::getSort).orderByDesc(Category::getUpdateTime);
List<Category> list = categoryService.list(queryWrapper);
return R.success(list);
}
Table
-
过滤器的使用
基础使用 -
自定义过滤器
1
2
3
4
5
6
7// 时间长忘记
vue 是有过滤器配置项 以下为 vue 配置项中的过滤器
filters: {
// 过滤价格显示
filterPrice(price) {
return '¥' + parseFloat(price).toFixed(2)
}
}-
需求
1
// 实现数据库查询,
对价格显示进行格式化操作 渲染 -
数据库数据
数据库原始数据格式 -
表格使用布局
布局结构
-
综合表单初始值确定
1 |
<template> |
初始值类型 |
---|
![]() |
GiteePages 部署测试
-
路由模式不能是
history
-
配置
vue.config.js
1
2
3
4
5
6
7
8
9
10
11const {defineConfig} = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
publicPath: process.env.NODE_ENV === 'production'
? '/element-ui/'
: '/'
})
# 修改为需要部署到的仓库 Eg: element-ui,部署时选择对应打包的静态文件分支部署即可
# 部署后的地址会添加上仓库地址 https://coder-itl.gitee.io/element-ui/#/index
# 如果不进行配置,是无法进行访问的 仓库信息 -
gitee
部署测试
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 coder-itl!
评论