上一篇博客写了一个基于element ui的表单表格处理页面的二次封装(可前往我的上一篇博客查看代码)这几天完善了一下,贴下代码,FullTable继承了大部分的el-table组件的attribute,除了树形表格和多选列表,详情可以查看element ui关于el-table的文档。对比上篇博客的版本,增加了表单校验
有默认的校验规则为:
rules: { [props]: [ {required: true, message: "请输入内容", trigger: [ "blur", "change" ] } ] }
不传入rules不校验,
传入空rules开启默认校验,例如
rules:{}//开启默认校验
传入自定义rules 的 prop 可替代原来的校验规则,没有传入prop的依然开启默认校验,例如:
rules:{ age: [ { required: true, type: "number", message: "年龄必须为数字值" }, { min: 0, max: 150, type: "number", message: "请输入正确的年龄" }, ], } //其他的依旧为 rules: { [props]: [ {required: true, message: "请输入内容", trigger: [ "blur", "change" ] } ] }
传入prop的值为空则取消校验,其他的依旧为默认校验 例如
rules:{ age: []//不校验age }
新增了移动端适配
//FullTable.vue
<template>
<div class="tableFont">
<el-button class="createBtn" v-if="permissionList.indexOf('C')!=-1" size="mini" @click="handleCreate">Create +</el-button>
<el-button class="delectBtn" v-if="permissionList.indexOf('D')!=-1" type="danger" plain size="mini" @click="handleBatchDelect">BatchDelect</el-button>
<el-table :data="newData.length==0?data:newData" style="width: 100%" :highlight-current-row="highlightCurrentRow" :current-row-key="currentRowKey" :row-class-name="rowClassName" :row-style="rowStyle" :cell-class-name="cellClassName" :cell-style="cellStyle" :header-row-style="headerRowStyle" :header-row-class-name="headerRowClassName" :header-cell-class-name="headerCellClassName" :max-height="maxHeight" :show-header="showHeader" :height="height" :fit="fit" :border="border" :stripe="stripe" :header-cell-style="headerCellStyle" :empty-text="emptyText" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center">
</el-table-column>
<el-table-column v-for="(prop,index) in propsKey" :key="index" :label="!keyLabel[index]?prop:keyLabel[index]" :prop="prop&