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>
相关推荐
paopaokaka_luck2 分钟前
智能推荐社交分享小程序(websocket即时通讯、协同过滤算法、时间衰减因子模型、热度得分算法)
数据库·vue.js·spring boot·后端·websocket·小程序
iccb101324 分钟前
我是如何实现在线客服系统的极致稳定性与安全性的
前端·javascript·后端
一大树25 分钟前
Vue3祖孙组件通信方法总结
前端·vue.js
宇宙全栈Link29 分钟前
当 React 组件调用自定义 hooks,hooks 又调用其他 hooks 时,状态变化如何传播?
前端·javascript·react.js
南方kenny30 分钟前
从0到1理解JS事件委托:让你的代码性能提升一个level
前端·javascript
西瓜树枝30 分钟前
用 iframe 实现前端批量下载的优雅方案 —— 从原理到实战
前端·javascript
coder_zhx31 分钟前
Vue3自定义编程式弹窗
前端·vue.js
归于尽31 分钟前
原生JS与React的事件差异
前端·javascript·react.js
独立开阀者_FwtCoder1 小时前
面试官:为什么在 Vue3 中 ref 变量要用 .value?
前端·javascript·vue.js
NetX行者1 小时前
基于Vue 3的AI前端框架汇总及工具对比表
前端·vue.js·人工智能·前端框架·开源