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>
相关推荐
J***Q2923 小时前
Vue数据可视化
前端·vue.js·信息可视化
JIngJaneIL4 小时前
社区互助|社区交易|基于springboot+vue的社区互助交易系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·社区互助
ttod_qzstudio5 小时前
深入理解 Vue 3 的 h 函数:构建动态 UI 的利器
前端·vue.js
芳草萋萋鹦鹉洲哦5 小时前
【elemen/js】阻塞UI线程导致的开关卡顿如何优化
开发语言·javascript·ui
1***s6325 小时前
Vue图像处理开发
javascript·vue.js·ecmascript
一 乐5 小时前
应急知识学习|基于springboot+vue的应急知识学习系统(源码+数据库+文档)
数据库·vue.js·spring boot
槁***耿5 小时前
JavaScript在Node.js中的事件发射器
开发语言·javascript·node.js
一叶茶6 小时前
移动端平板打开的三种模式。
前端·javascript
U***49836 小时前
JavaScript在Node.js中的Strapi
开发语言·javascript·node.js
老前端的功夫6 小时前
前端浏览器缓存深度解析:从网络请求到极致性能优化
前端·javascript·网络·缓存·性能优化