完善element ui 表格表单页面二次封装(接上一篇博客)

        上一篇博客写了一个基于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&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值