vue el-table表头加必填符号*

5 篇文章 0 订阅
5 篇文章 0 订阅

方法一

1.el-table表头加必填符号*及必填校验

<el-form :model="tableForm" ref="tableForm" :rules="rules" size="small">
     <el-table :data="tableForm.data" border>
	 <el-table-column >
	   <template slot="header">
	     <span style="color:#f67979">*</span>
	     <span class="tableHeader"> content</span>
	   </template>
	   <template slot-scope="scope">
	       <el-form-item
	         :prop="`data[${scope.$index}].validityDate`"
	         :rules="rules.validityDate"
	       >
	         <el-input
	              type="text"
	              v-model="scope.row.validityDate"
	            />
	       </el-form-item>
	   </template>
	 </el-table-column>
	 <el-table-column
            v-if="viewStatus != 'view'"
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="80"
          >
            <template slot-scope="scope">
              <i
                class="el-icon-plus"
                style="color: #409eff;
                  font-weight: bold;
                  cursor: pointer;
                  font-size: 18px;
                "
                @click="handleStandardadd"
                v-if="scope.$index == 0"
              ></i>
              <i
                class="el-icon-minus"
                style="
                  color: #f56c6c;
                  font-weight: bold;
                  cursor: pointer;
                  font-size: 18px;
                "
                @click="handleDelete(scope.$index)"
                v-else
              ></i>
            </template>
        </el-table-column>
        <el-button @click='submit'>提交</el-button>
	</el-table>
</el-form>

 data() {
    return {
      tableForm:{
	      data: [
	        {
	          validityDate: "",
	        },
	      ],
   	 },
      rules: {
        validityDate: [
          {
            required: true,
            message: '必填项不能空',
            trigger: 'change'
          }
        ],
   }
 },
  watch: {
    'tableForm.data': {
      handler: function (val) {
        if (val?.length) {
          this.$emit("", val);
        }
      },
      deep: true,
      immediate: true,
   },
 }methods:{
	 //动态加一行table
	 handleStandardadd() {
	      this.tableForm.data.push({
	        validityDate: "",
	      });
	  },
	  //动态删除
	 handleDelete(index) {
     	 this.tableForm.data.splice(index, 1)
     },
     submit() {
      console.log(tableData)
      this.$refs.tableForm.validate((valid) => {
       console.log(valid)
      })
    }, 
    

方法二

 <el-table-column label="content" align="center" 
	 :render-header="addRedStar"
	 >
    <template slot-scope="scope">
      <el-inputtype="text" v-model="scope.row.content" class="EltabelInput"
      />
    </template>
  </el-table-column>


---------------------------------
 methods: {
     // 给表头加必填符号*
    addRedStar(h, { column }) {
      return [
        h("span", { style: "color: red" }, "*"),
        h("span", " " + column.label),
      ];
    },
 }

第三种

忘了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值