思路:
一.添加一行数据
就是在添加的时候新建一个key值和表行key值一抹一样的对象
let j = {
"type": "",
"addport": "",
"user": "",
"pwd": "",
"info": "",
"isSet": true,
};
二.编辑一行的数据
就是根据isSet的存在与否来判断这一行是input显示(可编辑状态)还是span显示(不可编辑状态)
<template slot-scope="scope"> <span v-if="scope.row.isSet"> <el-input size="mini" placeholder="请输入内容" v-model="master_user.sel[item.prop]"> </el-input> </span> <span v-else>{{scope.row[item.prop]}}</span> </template>
三.删除一行
就是拿到这一行的索引值,然后用数组的splice()删除就好
deleteRow(index, rows) { //删除 rows.splice(index, 1) }
全部代码 ps:这里的代码是需要在vue-cli脚手架上面来运行的啊,相信小伙伴在做这个功能的时候,应该已经会用vue-cli了吧,对了,style后面是用的sass 如果不会sass,又想运行我的代码,建议删掉style.
<template> <div id="app"> <el-row> <el-col :span="24"> <el-table size="mini" :data="master_user.data" border style="width: 100%" highlight-current-row> <el-table-column type="index"></el-table-column> <el-table-column v-for="(item,index) in master_user.columns" :label="item.label" :prop="item.prop" :width="item.width"> <template slot-scope="scope"> <span v-if="scope.row.isSet"> <el-input size="mini" placeholder="请输入内容" v-model="master_user.sel[item.prop]"> </el-input> </span> <span v-else>{{scope.row[item.prop]}}</span> </template> </el-table-column> <el-table-column label="操作" width=""> <template slot-scope="scope"> <span class="el-tag el-tag--success el-tag--mini" style="cursor: pointer;" @click.stop="saveRow(scope.row,scope.$index)"> 确定 </span> <span class="el-tag el-tag--primary el-tag--mini" style="cursor: pointer;" @click="editRow(scope.row,scope.$index)"> 编辑 </span> <span class="el-tag el-tag--danger el-tag--mini" style="cursor: pointer;" @click="deleteRow(scope.$index,master_user.data)"> 删除 </span> </template>