• eltable实现增加行、删除行


    原文链接: https://blog.csdn.net/ahwangzc/article/details/122936566

    <template>
    <div class="tableDate">
    <div class="button" style="6%;float:right;">
    <P><el-button class="el-icon-plus" @click.prevent="addRow()"></el-button></P>
    <p><el-button class="el-icon-minus" @click.prevent="delData()"></el-button></p>
    </div>
    <div class="table">
    <el-table
    :data="tableData"
    ref="table"
    tooltip-effect="dark"
    border
    stripe
    style=" 93%"
    @selection-change='selectRow'>
    <el-table-column type="selection" width="45" align="center"></el-table-column>
    <el-table-column label="序号" type="index" width="60" align="center"></el-table-column>
    <el-table-column label="岗位" align="center">
    <template slot-scope="scope">
    <el-cascader prop="post_id" class="post_name" v-model="scope.row.post_id" :options="post_options" :show-all-levels="false" @change="test"></el-cascader>
    <!--<el-input v-model="scope.row.post_id"></el-input>-->
    </template>
    </el-table-column>
    <el-table-column label="需求">
    <template slot-scope="scope">
    <el-input class="require_des" v-model="scope.row.require_des"></el-input>
    </template>
    </el-table-column>
    <el-table-column label="备注">
    <template slot-scope="scope">
    <el-input type="textarea" class="remark" v-model="scope.row.remark"></el-input>
    </template>
    </el-table-column>

    </el-table>
    </div>
    </div>
    </template>


    <script>
    export default {
    data () {
    return {
    tableData: [],
    selectlistRow: [],
    rowNum:1
    }
    },
    methods: {
    // 获取表格选中时的数据
    selectRow (val) {
    this.selectlistRow = val
    },
    // 增加行
    addRow () {
    var list = {
    rowNum:this.rowNum,
    post_id:[],
    require_des: '',
    remark:''
    };
    this.tableData.unshift(list)
    this.rowNum += 1;
    },
    // 删除方法
    // 删除选中行
    delData () {
    for (let i = 0; i < this.selectlistRow.length; i++) {
    let val = this.selectlistRow
    // 获取选中行的索引的方法
    // 遍历表格中tableData数据和选中的val数据,比较它们的rowNum,相等则输出选中行的索引
    // rowNum的作用主要是为了让每一行有一个唯一的数据,方便比较,可以根据个人的开发需求从后台传入特定的数据
    val.forEach((val, index) => {
    this.tableData.forEach((v, i) => {
    if (val.rowNum === v.rowNum) {
    // i 为选中的索引
    this.tableData.splice(i, 1)
    }
    })
    })
    }
    // 删除完数据之后清除勾选框
    this.$refs.table.clearSelection()
    }
    }
    }
    </script>

  • 相关阅读:
    解决mysql因为服务名无效启动不了
    新手上路遇到的Whitelabel Error Page解决方案
    解决报错java.lang.UnsatisfiedLinkError: F:J2EEapache-tomcat-8.5.46in cnative-1.dll:Can't load AMD 64
    安装sqlserver导致80端口被占用解决方法
    【计算机网络】-传输层-Internet传输协议-UDP
    【计算机网络】-传输层-Internet传输协议-TCP
    【计算机网络】-传输层-拥塞控制
    文件系统-文件的物理结构与存储设备
    vant封装城市/联系人等选择器
    I5TING_TOC转成的HTML,怎样高亮代码
  • 原文地址:https://www.cnblogs.com/fswhq/p/16715664.html
Copyright © 2020-2023  润新知