vue + element-ui 实现表格 增加 删除 行 操作 以及 复选框实现

HTML 部分:

  <tr class="height320" style="border-top: 1px">
                  <td class="tdBg jianli_td lh18 textAlign">
                    <br><br></td>

                  <td colspan="6">
                    <el-form ref="inServForm" :model="inServForm" label-width="0px" size="small">
                      <el-form-item prop="servin">

                        <el-button type="primary" @click="addRow(infiledList)">新增简历</el-button>
                        <el-button type="primary" @click="addCheck(infiledList)">添加勾选</el-button>

                        <el-table border :data="infiledList" style="width: 100%">

                          <el-table-column :width="columnOtherWidth" label="复选">
                            <template slot-scope="scope">
                              <el-checkbox v-model="scope.row.isCheck" />
                            </template>
                          </el-table-column>

                          <el-table-column prop="fildna" :width="columnTimeWidth" label="开始时间">
                            <template scope="scope">
                              <el-input v-model="scope.row.isCheck" size="mini" />
                            </template>
                          </el-table-column>
                          <el-table-column prop="fildna" :width="columnTimeWidth" label="截止时间">
                            <template scope="scope">
                              <el-input v-model="scope.row.fildna" size="mini" />
                            </template>
                          </el-table-column>
                          <el-table-column prop="remark" :width="columnRemarkWidth" label="简历信息">
                            <template scope="scope">
                              <el-input v-model="scope.row.remark" size="mini" />
                            </template>
                          </el-table-column>
                          
                          <el-table-column prop="remark" label="任职年限">
                            <template scope="scope">
                              <el-input v-model="scope.row.remark" size="mini" />
                            </template>
                          </el-table-column>
                          <el-table-column prop="remark" label="任重要职务、重要经历标识说明">
                            <template scope="scope">
                              <el-input v-model="scope.row.remark" size="mini" />
                            </template>
                          </el-table-column>
                          
                          <el-table-column prop="remark" label="经历年限">
                            <template scope="scope">
                              <el-input v-model="scope.row.remark" size="mini" />
                            </template>
                          </el-table-column>
                          
                          <el-table-column fixed="right" label="操作">
                            <template slot-scope="scope">
                              <el-button size="small" @click.native.prevent="deleteRow(scope.$index, infiledList)"> 移除 </el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <!--                        </template>-->
                      </el-form-item>
                    </el-form>
                  </td>
                </tr>

                <tr>
                  <td class="tdBg height35 textAlign">
                    历任主要职务
                  </td>
                  <td class="formValue" colspan="12" align="left">
                    <textarea id="jqpyfx" v-model="getNewList" name="jqpyfx" style="width : 100%;" rows="4" maxlength="500" class="form-control " />
                  </td>
                </tr>
                <tr>
                  <td class="tdBg height35 textAlign">
                    历任重要职务重要经历标识
                  </td>
                  <td class="formValue" colspan="12" align="left">
                    <textarea id="jqpyfx" v-model="person.nationdesc" name="jqpyfx" style="width : 100%;" rows="4" maxlength="500" class="form-control " />
                  </td>
                </tr>
                <tr>
                  <td class="tdBg height35 textAlign">
                    工作经历细项
                  </td>
                  <td class="formValue" colspan="12" align="left">
                    <textarea id="jqpyfx" v-model="person.nationdesc" name="jqpyfx" style="width : 100%; height: 120px" rows="4" maxlength="500" class="form-control " />
                  </td>
                </tr>

数据部分:

data() {
    return {
      infiledList: [], // 简历信息(简历的所有信息)
      getNewList: '', // 勾选存放信息 复选框用
      isCheck: false, // 简历是否勾选 复选框用
      }
      }

方法部分:

methods: {
    // 简历删除行(移除)
    deleteRow(index, rows) {
      rows.splice(index, 1)
    },
    // 简历新增行(添加简历)
    addRow(tableData, event) {
      tableData.push({ fildna: '', fildtp: '', remark: ''
      })
    },
    // 添加勾选到历任主要职务(复选框勾选)
    addCheck() {
      this.getNewList = ''
      for (const item of this.infiledList) {
        // eslint-disable-next-line eqeqeq
        if (item.isCheck == true) {
          this.getNewList += item.remark + ','
        }
      }
    },
    }

效果图:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Element-UI的树形Table组件可以通过设置show-checkbox属性来显示框,但是默认情况下只会在非叶子节点上显示框,如果需要在最后一层也显示框,可以通过以下两种方式实现: 1. 使用slot-scope自定义单元格内容 在template中使用slot-scope自定义单元格内容,通过判断当前是否为最后一层来显示框。 ```html <el-table :data="data" style="width: 100%"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="name" label="名称"></el-table-column> <el-table-column label="操作"> <template slot-scope="{ row }"> <el-checkbox v-if="isLastLevel(row)" v-model="checkedNodes" :label="row.id"></el-checkbox> </template> </el-table-column> </el-table> ``` 在methods中定义isLastLevel方法来判断当前是否为最后一层: ```javascript methods: { isLastLevel(row) { return !row.children || row.children.length === 0; } } ``` 2. 使用tree-node-key属性指定叶子节点的key值 在使用树形数据时,可以通过tree-node-key属性指定叶子节点的key值,然后在show-checkbox属性中使用leaf-only来显示所有叶子节点的框。 ```html <el-table :data="data" :tree-props="{children: 'children', hasChildren: 'hasChildren', id: 'id', label: 'name', key: 'id'}" :tree-node-key="'id'" :show-checkbox="true" :leaf-only="true" style="width: 100%"> <el-table-column prop="name" label="名称"></el-table-column> <el-table-column label="操作"> <template slot-scope="{ row }"> <el-checkbox v-model="checkedNodes" :label="row.id"></el-checkbox> </template> </el-table-column> </el-table> ``` 在这种方式下,只需要在template中直接显示框即可,不需要判断当前是否为最后一层。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值