el-table 表格中插入表单循环校验

javascript 复制代码
<template>
  <div>
    {{form}}
    <el-form :model="form" ref="form">
      <el-form-item label="呃呃呃呃呃呃呃">
        <el-table :data="tableData" border>

          <el-table-column prop="time" label="日期" width="180">
            <template slot-scope="scope">
              <span>{{scope.row.cases}}</span>
              <span v-if="scope.$index > 6">
                <el-form-item :prop="'list.'+scope.$index+'.cancerName'">
                  <el-input v-model="form.list[scope.$index].cancerName" placeholder="请输入内容"></el-input>
                </el-form-item>
              </span>
            </template>
          </el-table-column>

          <el-table-column prop="screeningCount" label="总数" width="180">
            <template slot-scope="scope">
              <el-form-item :prop="'list.'+scope.$index+'.screeningCount'">
                <el-input v-model="form.list[scope.$index].screeningCount" placeholder="请输入内容"></el-input>
              </el-form-item>
            </template>
          </el-table-column>

          <el-table-column label="单选" width="180">
            <template slot-scope="scope">
              <el-form-item :prop="'list.'+scope.$index+'.percentage'">
                <el-radio-group v-model="form.list[scope.$index].percentage">
                  <el-radio label="线上品牌商赞助"></el-radio>
                  <el-radio label="线下场地免费"></el-radio>
                </el-radio-group>
              </el-form-item>
            </template>
          </el-table-column>

          <div slot="append">
            <i class="el-icon-circle-plus-outline" @click="add"></i>
            <i class="el-icon-circle-close" @click="del"></i>
          </div>

        </el-table>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">确认</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {
        list: [
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' },
          { cancerName: '', screeningCount: '', percentage: '' }
        ]
      },
      tableData: [
        { cases: '学不会1' },
        { cases: '学不会2' },
        { cases: '学不会3' },
        { cases: '学不会4' },
        { cases: '学不会5' },
        { cases: '学不会6' },
        { cases: '学不会7' }
      ]
    }
  },
  methods: {
    add () {
      this.tableData.push(
        { cases: `其他${this.tableData.length - 6}` }
      )
      this.form.list.push(
        { cancerName: '', screeningCount: '', percentage: '' }
      )
    },
    del () {
      this.tableData.pop()
      this.form.list.pop()
    }
  }
}
</script>

<style lang="less" scoped>
.el-icon-circle-plus-outline,
.el-icon-circle-close {
  font-size: 26px;
  cursor: pointer;
  margin-left: 20px;
}
</style>
相关推荐
dorabighead1 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript
林的快手3 小时前
CSS列表属性
前端·javascript·css·ajax·firefox·html5·safari
bug总结4 小时前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
网络安全-老纪4 小时前
网络安全-js安全知识点与XSS常用payloads
javascript·安全·web安全
yqcoder4 小时前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
十八朵郁金香4 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
计算机-秋大田5 小时前
基于Spring Boot的兴顺物流管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·spring·课程设计
GDAL5 小时前
HTML 中的 Canvas 样式设置全解
javascript
GDAL5 小时前
HTML Canvas clip 深入全面讲解
前端·javascript·canvas
禾苗种树5 小时前
在 Vue 3 中使用 ECharts 制作多 Y 轴折线图时,若希望 **Y 轴颜色自动匹配折线颜色**且无需手动干预,可以通过以下步骤实现:
前端·vue.js·echarts