Elemnt ui 组件封装(form)
<template>
<el-form
class="form"
:inline="formConfig.inline"
:model="value"
:label-width="formConfig.labelWidth"
:rules="rules"
:size='formConfig.size'
>
<slot name="formItem" />
<el-form-item
v-for="(item,index) in formConfig.formItemList"
:key="index"
:label="item.label"
:prop="item.prop"
:width="formConfig.width"
>
<el-input
v-if="item.type=='input'"
v-model="value[item.prop]"
:disabled="item.disabled"
:clearable="true"
:placeholder="item.placeholder"
></el-input>
<el-select
:clearable="true"
v-else-if="item.type=='select'"
v-model="value[item.prop]"
:disabled="item.disabled"
:placeholder="item.placeholder"
>
<el-option
v-for="(optItem,index) in item.optList"
:key="index"
:label="optItem.label"
:value="optItem.value"
></el-option>
</el-select>
<el-date-picker
:value-format="item.dateFormate"
v-else
v-model="value[item.prop]"
:type="item.type"
:disabled="item.disabled"
:clearable="true"
:placeholder="item.label"
></el-date-picker>
</el-form-item>
<div class="searchBtn">
<el-button-group>
<el-button
class="btn"
v-for="(item, index) in formConfig.operate"
:key="index"
:size="item.size"
:type="item.type"
:icon="item.icon"
@click="item.handleClick(value)"
>{{item.name}}
</el-button>
</el-button-group>
<slot name="operate"></slot>
</div>
</el-form>
</template>
<script>
export default {
components: {},
props: {
formConfig: {
type: Object,
required: true
},
value: {
type: Object,
required: true
},
rules: {
type: Object
}
},
computed: {},
methods: {
setDefaultValue() {
const formData = { ...this.value };
// 设置默认值
this.formConfig.formItemList.forEach(({ key, value }) => {
if (formData[key] === undefined || formData[key] === null) {
formData[key] = value;
}
});
}
},
mounted() {
this.setDefaultValue();
}
};
</script>
<style lang="scss" scoped>
.form {
min-width: 300px;
}
.searchBtn {
.btn {
margin-left: 20px;
}
}
</style>
formConfig配置
formConfig: {
inline: true,
size: "normal",
labelWidth: '100',
width: '180',
formItemList: [
{label: '商品名称',prop: 'name',type: 'input', placeholder: '请输入商品名称'},
{label: '进价',prop: 'incode',type: 'input', placeholder: '请输入进价'},
{label: '售价',prop: 'expend',type: 'input', placeholder: '请输入售价'},
{label: '库存数量',prop: 'number',type: 'input', placeholder: '请输入库存数量'},
{label: '商品描述',prop: 'remark',type: 'input', placeholder: '请输入商品描述'},
{label: '供应商',prop: 'resource',type: 'input', placeholder: '请输入供应商'}
],
operate: [
{type: 'primary',icon: '',name: '取消',size: 'normal',handleClick: function() {}},
{type: 'primary',icon: '',name: '确定',size: 'normal',handleClick: (form) => {
this.handleSubmit(form);
}},
]
}
Elemnt ui 组件封装(form)的更多相关文章
- Elemnt ui 组件封装(table)
<template> <div class="table"> <el-table :data="tableData2" :bord ...
- 前端如何搭建vue UI组件库/封装插件(从零到有)
需求 因之前是做外包项目居多,经常用到相同的组件,之前的办法是在一个项目中写一个组件,其他项目直接将compents下的组件复制,粘贴到项目中使用,缺点是维护起来,改一个项目,其他项目也需要修改,所以 ...
- Vue + Element UI 实现权限管理系统 (功能组件封装)
组件封装 为了避免组件代码的臃肿,这里对主要的功能部件进行封装,保证代码的模块化和简洁度. 组件结构 组件封装重构后,试图组件结构如下图所示 代码一览 Home组件被简化,包含导航.头部和主内容三个组 ...
- Vue + Element UI 实现权限管理系统 前端篇(七):功能组件封装
组件封装 为了避免组件代码的臃肿,这里对主要的功能部件进行封装,保证代码的模块化和简洁度. 组件结构 组件封装重构后,试图组件结构如下图所示 代码一览 Home组件被简化,包含导航.头部和主内容三个组 ...
- DCloud-MUI:文档 UI组件
ylbtech-DCloud-MUI:文档 UI组件 1.返回顶部 1.accordion(折叠面板) 折叠面板从二级列表中演化而来,dom结构和二级列表类似,如下: <ul class=&qu ...
- [开源] 基于Layui组件封装的后台模版,HG-Layui-UI通用后台管理框架V1.0版
HG框架简介 HG-Layui-UI框架,是基于layui最新版UI搭建的一套通用后台管理框架,借鉴了市面上各大主流框架风格,采用iframe标签页实现,保留了传统开发模式的简单实用性. 为快速开发减 ...
- Element Ui使用技巧——Form表单的校验规则rules详细说明
Element UI中对Form表单验证的使用介绍: Form 组件提供了表单验证的功能,只需要通过 rules 属性传入约定的验证规则,并将 Form-Item的 prop 属性设置为需校验的字段名 ...
- Atitit.web ui 组件化 vs mvc
Atitit.web ui 组件化 vs mvc 组件化 与 mvc并不矛盾..单双方适用的地方有所不同.. React推荐以组件的方式去重新思考UI构成,将UI上每一个功能相对独立的模块定 ...
- AngularJs的UI组件ui-Bootstrap分享(七)——Buttons和Dropdown
在ui-Bootstrap中,Buttons控件和Dropdown控件与form表单中的按钮和下拉框名字很像,但实际上这两个控件有新的含义. 先说Buttons,它是一组按钮,用来实现form表单中的 ...
随机推荐
- 洛谷 P1020 [NOIP1999 普及组] 导弹拦截
Coidng #include <iostream> #include <algorithm> #include <cstring> #include <ve ...
- HDFS机架感知
Hadoop版本:2.9.2 什么是机架感知 通常大型 Hadoop 集群是以机架的形式来组织的,同一个机架上的不同节点间的网络状况比不同机架之间的更为理想,NameNode 设法将数据块副本保存在不 ...
- 【freertos】003-任务基础知识
目录 前言 任务概念 任务状态 任务优先级 空闲任务和空闲任务钩子 空闲任务 空闲任务钩子 创建空闲钩子 创建任务 任务参数相关概念 创建静态内存任务 配置静态内存 实现空闲任务堆栈函数 实现定时器任 ...
- mac安装git
https://blog.csdn.net/shaock2018/article/details/91127607 继续报错 rm -rf /usr/local/Homebrew/Library/Ta ...
- 什么是openssl?
在计算机网络上,OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份.这个包广泛被应用在互联网的网页服务器上.
- 接口是否可继承(extends)接口?抽象类是否可实现(implements)接口?抽象类是否可继承具体类(concrete class)?
接口可以继承接口,而且支持多重继承.抽象类可以实现(implements)接口,抽象类可继承具体类也可以继承抽象类.
- 学习Puppet(三)
一.相关概念: 1. puppet基于C/S架构,使用ruby编写,在类UNIX平台上集中配置管理系统,它可以管理配置文件.用户.cron任务.软件包.系统服务. 2. puppet把系统实体称为 ...
- Spark学习摘记 —— Pair RDD行动操作API归纳
本文参考 参考<Spark快速大数据分析>动物书中的第四章"键值对操作",本篇是对RDD转化操作和行动操作API归纳的最后一篇 RDD转化操作API归纳:https:/ ...
- MySQL优化篇(一),我可以和面试官多聊几句吗?——SQL优化流程与优化数据库对象
我可以和面试官多聊几句吗?只是想偷点技能过来.MySQL优化篇(基于MySQL8.0测试验证),上部分:优化SQL语句.数据库对象,MyISAM表锁和InnoDB锁问题. MyISAM表锁和InnoD ...
- Unsafe Rust 能做什么
在不安全的 Rust 中唯一不同的是,你可以: 对原始指针进行解引用 调用"不安全"的函数(包括 C 函数.编译器的内建指令和原始分配器. 实现"不安全"的特性 ...