实习开发中发现经常会有表格检验的需求,目前我遇到的做法是判断表格是否为空然后提示即可,以后要用到rule规则检验的我再记录。
效果如图(其中的星号是自己画上去的,,,,)
在computed里面写计算方法
checkForm () {
let check = true
if (this.form.annexInfos.length != 0) {
this.form.annexInfos.forEach(e => {
if (e.annexDate == '') {
check = false
}
});
}
return check
},
然后是点击保存后触发
save(status) {
if (!this.checkForm ) {
this.$message.error("请检查数据是否输入完整");
return;
}//下面是不为空触发的后端请求等方法
}
最后是通过插槽给表格头添加星号
步骤一:给表格对应列添加插槽
{
dataIndex: "annexDate",
// title: "附件有效期至,
scopedSlots: { customRender: "annexDate", title: "customName" }
}
步骤二:修改表头文字(后面的是表格每行的时间选择框)
<span slot="customName">
<i class="toRequired">*</i>附件有效期至
</span>
<template slot="annexDate"
slot-scope="text, record">
<a-date-picker :locale="locale"
format="YYYY-MM-DD"
v-model="record.annexDate"
valueFormat="YYYY-MM-DD" />
<div v-show="!record.annexDate && showAnnexError"
class="show-error">
请选择附件有效期
</div>
</template>
步骤三:css画星号
.toRequired {
color: #ff4949;
padding-right: 2px;
}