Vue+Element实现表格的编辑、删除、以及新增行

方案一、原生表格

1、页面效果

在这里插入图片描述

2、实现

速度发送方打赏

3、定义
addRow:[{configInfo:{fieldEnglishName:'',fieldChineseName:'',totalType:'',fieldLength:'',isNotNull:'',primaryKey:'',remark:'',isNotSelected:'0'}}],

方案二、element表格

1、页面效果

在这里插入图片描述

2、实现
<el-button type="primary" plain icon="el-icon-circle-plus-outline" size="small" @click="addRow(infiledList)">添加</el-button>
     <el-table :data="infiledList">
        <el-table-column  prop="url" label="文件上传" >
           <el-upload
             ref="proPic"
             class="upload-demo"
             :action="upload.url"
             :headers="upload.headers"
             :on-preview="handlePreview"
             :on-remove="handleRemove"
             :file-list="fileList"
             :limit="1"
             :on-progress="onProgress"
             :on-success="handleFileSuccess"
             :auto-upload="true"
             list-type="picture">
             <el-button size="small" type="primary">点击上传</el-button>
           </el-upload>
         </el-table-column>
          <el-table-column prop="nowName" label="新名称" >
             <template slot-scope="scope">
                 <el-input v-model="scope.row.nowName" clearable placeholder="请输新名称"></el-input>
             </template>
           </el-table-column>
           <el-table-column prop="accessoryType" label="附件类型" >
             <template slot-scope="scope">
                 <el-select class="width100" clearable v-model="scope.row.accessoryType" >
                     <el-option v-for="item in accessoryTypeList" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
                 </el-select>
             </template>
           </el-table-column>
           <el-table-column  label="操作">
             <template slot-scope="scope">
                 <el-button plain type="danger" @click.native.prevent="deleteRow(scope.$index, infiledList)" size="small"> 移除 </el-button>
             </template>
           </el-table-column>

     </el-table>
3、定义
  infiledList:[],

methods:{
	//可追加的模块
    deleteRow(index, rows) {//删除改行
      console.log('删除行--',index, rows)
      rows.splice(index, 1);
    },
    addRow(tableData,event){
      console.log('添加行--',tableData,event)
       tableData.push({ nowName: '',accessoryType:''
      })
     },
}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VueElement UI中添加一个新增功能,你需要完成以下步骤: 1. 首先,在你的Vue组件中引入Element UI中的表格组件,并确保你已经正确安装了Element UI: ```javascript import { Table, TableColumn, Dialog, Button } from 'element-ui'; ``` 2. 在你的Vue组件模板中,添加一个表格组件,并将数据绑定到表格的data属性上: ```html <template> <div> <el-table :data="tableData"> <el-table-column prop="name" label="Name"></el-table-column> <el-table-column prop="age" label="Age"></el-table-column> <el-table-column prop="address" label="Address"></el-table-column> <el-table-column label="Operation"> <template slot-scope="scope"> <el-button @click="edit(scope.row)">Edit</el-button> <el-button @click="delete(scope.row)">Delete</el-button> </template> </el-table-column> </el-table> </div> </template> ``` 3. 添加一个按钮或其他交互元素,以触发新增事件。在点击事件中,使用Element UI的Dialog组件显示一个对话框,用于输入新增数据: ```html <template> <div> <el-button @click="showAddDialog">Add</el-button> <el-table :data="tableData"> <!-- table columns... --> </el-table> <el-dialog title="Add New Entry" :visible.sync="addDialogVisible"> <!-- form fields... --> </el-dialog> </div> </template> <script> export default { data() { return { tableData: [], addDialogVisible: false, formData: {} // 新增表单数据 }; }, methods: { showAddDialog() { this.addDialogVisible = true; }, addRow() { // 将新增数据添加表格数据中 this.tableData.push(this.formData); // 关闭对话框并重置表单数据 this.addDialogVisible = false; this.formData = {}; } } } </script> ``` 4. 在对话框中添加表单元素,以允许用户输入新增数据。你可以使用Element UI的Form和FormItem组件来创建表单: ```html <el-dialog title="Add New Entry" :visible.sync="addDialogVisible"> <el-form :model="formData"> <el-form-item label="Name"> <el-input v-model="formData.name"></el-input> </el-form-item> <el-form-item label="Age"> <el-input v-model="formData.age"></el-input> </el-form-item> <el-form-item label="Address"> <el-input v-model="formData.address"></el-input> </el-form-item> </el-form> <div slot="footer"> <el-button @click="addRow">Confirm</el-button> <el-button @click="addDialogVisible = false">Cancel</el-button> </div> </el-dialog> ``` 这样,你就可以在VueElement UI中添加一个表格新增功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值