vue使用el-table 添加行手动填写数据和删除行及提交保存功能

 更新时间:2023年12月21日 14:16:19   作者:MXin5  
遇到这样的需求点击新增按钮实现下列弹窗的效果,点击添加行新增一行,点击删除进行删除行,点击提交将数据传递到后端进行保存,怎么实现的呢,下面通过实例代码给大家详细讲解,感兴趣的朋友一起看看吧

        需求:点击新增按钮实现下列弹窗的效果,点击添加行新增一行,点击删除进行删除行,点击提交将数据传递到后端进行保存。

代码

      <el-dialog :title="titleDataDictionary" :visible.sync="openDataDictionary" width="1300px" append-to-body>
        <el-button type="primary" class="add-btn" @click="addDemo">添加行</el-button>
        <el-table
          :data="tableData"
          size="mini"
          stripe
          highlight-current-row
          border
          style="width: 97.3%"
          class="el-tb-edit"
          :header-cell-style="{
        background: '#2a87ed',
        color: '#fff',
        fontSize: ' 1.2rem',
        fontWeight: 'normal',
        height: '2.88rem',
      }"
          ref="demoTable"
        >
          <el-table-column prop="index" label="序号" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.index"></el-input>
              <!--              <span>{{ scope.row.index }}</span>  显示在输入框的下面-->
            </template>
          </el-table-column>
          <el-table-column prop="assetNo" label="资产编号" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.assetNo"></el-input>
            </template>
          </el-table-column>
          <!-- <el-table-column type="index" width="50">序号</el-table-column> -->
          <el-table-column prop="riskSourceName" label="表中文名" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.riskSourceName"></el-input>
            </template>
          </el-table-column>
          <el-table-column prop="riskPointName" label="表英文名" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.riskPointName"></el-input>
              <!--              <span>{{ scope.row.riskPointName }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="riskLevel" label="字段中文名" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.riskLevel"></el-input>
              <!--              <span>{{ scope.row.riskLevel }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="hiddenDanger" label="字段类型" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.hiddenDanger"></el-input>
              <!--              <span>{{ scope.row.hiddenDanger }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="type" label="字段长度" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.type"></el-input>
              <!--              <span>{{ scope.row.type }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="accident" label="取值范围" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.accident"></el-input>
              <!--              <span>{{ scope.row.accident }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" width="120">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark"></el-input>
              <!--              <span>{{ scope.row.remark }}</span>-->
            </template>
          </el-table-column>
          <el-table-column prop="accident" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDeleteDataDictionary(scope.$index,tableData)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-button type="primary" class="add-btn" @click="handleDataDictionaryAssetInfo">提交</el-button>
      </el-dialog>

data

      data(){
        return{
          //录入数据字典资产信息
          dataId: 1,
          //数据字典资产信息的集合
          tableData: [],
          //数据字典资产信息录入
          openDataDictionary: false,
          //数据字典资产信息录入弹出框标题
          titleDataDictionary: "",
        }
      }

methods

methods: {
    /** 删除按钮操作 */
    handleDeleteDataDictionary(index, rows) {
      alert("index" + index);//这个index就是当前行的索引坐标
      this.$modal.confirm('是否删除当前行?').then(function () {
        rows.splice(index, 1); //对tableData中的数据删除一行
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    //   添加行
    addDemo() {
      var d = {
        index: this.dataId++,
        assetNo: "", //资产编号实时回显
        riskSourceName: "",
        riskLevel: "",
        riskPointName: "",
        type: "",
        hiddenDanger: "",
        dangerLevel: "",
        accident: "",
        remark: ""
      };
      this.tableData.push(d);
      setTimeout(() => {
        this.$refs.demoTable.setCurrentRow(d);
      }, 10);
    },
    /**
     * 数据字典资产信息录入点击提交执行的方法
     * */
    handleDataDictionaryAssetInfo() {
      addDataDictionaryAssetInfo(this.tableData).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.open = false;
      });
    },

到此这篇关于vue采用el-table 添加行手动填写数据和删除行及提交的文章就介绍到这了,更多相关vue el-table 添加行删除行内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue-seamless-scroll 实现简单自动无缝滚动且添加对应点击事件的简单整理

    vue-seamless-scroll 实现简单自动无缝滚动且添加对应点击事件的简单整理

    vue-seamless-scroll是一个基于Vue.js的简单无缝滚动组件, 基于requestAnimationFrame实现,配置多满足多样需求,目前支持上下左右无缝滚动,单步滚动,及支持水平方向的手动切换功能,本节介绍,vue添加 vue-seamless-scroll实现自动无缝滚动的效果,并对应添加点击事件
    2023-01-01
  • Vue装饰器中的vue-property-decorator 和 vux-class使用详解

    Vue装饰器中的vue-property-decorator 和 vux-class使用详解

    这篇文章主要介绍了Vue装饰器中的vue-property-decorator 和 vux-class使用详解,通过示例代码给大家介绍的非常详细,对vue-property-decorator 和 vux-class的使用感兴趣的朋友一起看看吧
    2022-08-08
  • Vue模拟键盘组件的使用和封装方法

    Vue模拟键盘组件的使用和封装方法

    文章详细介绍了如何封装和使用Vue模拟键盘组件,涵盖了组件封装方法以及使用技巧,还提供了扩展方法,如新增键盘类型和添加动画效果,并强调了事件处理、响应式设计和无障碍支持的关键点,需要的朋友可以参考下
    2025-10-10
  • vue选项卡组件的实现方法

    vue选项卡组件的实现方法

    这篇文章主要为大家详细介绍了vue选项卡组件的实现方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • Vue网络请求的三种实现方式介绍

    Vue网络请求的三种实现方式介绍

    这篇文章主要介绍了Vue网络请求的三种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-09-09
  • 在Vue中实现网页截图与截屏功能详解

    在Vue中实现网页截图与截屏功能详解

    在Web开发中,有时候需要对网页进行截图或截屏,Vue作为一个流行的JavaScript框架,提供了一些工具和库,可以方便地实现网页截图和截屏功能,本文将介绍如何在Vue中进行网页截图和截屏,需要的朋友可以参考下
    2023-06-06
  • 前端架构vue动态组件使用基础教程

    前端架构vue动态组件使用基础教程

    这篇文章主要为大家介绍了前端架构vue动态组件使用的基础教程,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪
    2022-02-02
  • vue-cli脚手架搭建方式(vue脚手架方式搭建)

    vue-cli脚手架搭建方式(vue脚手架方式搭建)

    这篇文章主要介绍了vue-cli(vue脚手架方式搭建),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • Vue2实现Office文档(docx、xlsx、pdf)在线预览功能

    Vue2实现Office文档(docx、xlsx、pdf)在线预览功能

    在现代的Web应用开发中,实现Office文档(如docx、xlsx、pdf)的在线预览功能是一个常见的需求,下面小编就来和大家详细介绍一下如何使用vue2实现这一功能吧
    2025-05-05
  • Vue+Element实现页面生成快照截图

    Vue+Element实现页面生成快照截图

    这篇文章主要为大家详细介绍了Vue如何结合Element实现页面生成快照截图功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下
    2024-03-03

最新评论