项目需求表格的内容显示和修改框切换显示
如图所示,点击修改按钮切换到输入框和选择框
点击前:

点击后:

1.首先先定义一个变量用来控制span和input的显示隐藏,因为点击按钮只能修改该行数据,所以要给每行一个index作为标识
tem

<el-table-columnprop="rectPeriod"header-align="center"align="center"label="整改期限"width="180"><template slot-scope="{row,$index}">   //注意此处要写为row,写成scope会报错<span v-if="!showEdit[$index]">{{row.rectPeriod}}</span>  //用showEdit[$index]来控制显示隐藏<el-date-pickerv-model="rectPeriod[$index]"   //此处用$index来区分每行不同的日期选中值type="date"placeholder="选择日期"v-if="showEdit[$index]"value-format="yyyy-MM-dd"></el-date-picker></template>
</el-table-column>

js

export default {data(){return {//控制修改显示隐藏showEdit:[],//用来存储日期选中值rectPeriod:[]}},methods:{}
}

2.然后给修改按钮绑定点击事件,点击修改时showEdit[$index]为true
tem

<el-table-column
header-align="center"
align="center"
width="200"
label="操作"><template slot-scope="{row,$index}"><el-button v-if="!showEdit[$index]" @click="showUpdate($index,row)">修改</el-button><el-button v-if="showEdit[$index]" @click="submit(row)">确定</el-button><el-button v-if="showEdit[$index]" @click="cancelUpdate($index)">取消</el-button></template>
</el-table-column>

js

export default {data(){return {//控制修改显示隐藏showEdit:[],//用来存储日期选中值rectPeriod:[]}},methods:{//点击修改showUpdate(index,row){if(row.rectPeriod){this.rectPeriod[index] = row.rectPeriod    //回显}else {this.rectPeriod[index] = ''}this.showEdit[index] = true;this.$set(this.showEdit,index,true)   //这里要用$set方法,否则页面状态不更新},}
}

3.再给取消按钮和确定按钮绑定事件
tem

<el-table-column
header-align="center"
align="center"
width="200"
label="操作"
v-if="isAuth('govemment:rectification:update')"><template slot-scope="{row,$index}"><el-button v-if="!showEdit[$index]" @click="showUpdate($index,row)">修改</el-button><el-button v-if="showEdit[$index]" @click="submit($index,row)">确定</el-button><el-button v-if="showEdit[$index]" @click="cancelUpdate($index)">取消</el-button></template>
</el-table-column>

js

export default {data(){return {//控制修改显示隐藏showEdit:[],//用来存储日期选中值rectPeriod:[]}},methods:{//点击修改showUpdate(index,row){this.showEdit[index] = true;this.$set(this.showEdit,index,true)   //这里要用$set方法,否则页面状态不更新},//取消修改cancelUpdate(index){this.$confirm('取消修改?','提示',{confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(()=>{this.$set(this.showEdit,index,false) }).catch(() => {})},//提交修改submit(index,row){//发送请求,隐藏输入框this.$http({url: this.$http.adornUrl('/trouble/update'),method: 'post',params: this.$http.adornParams({'id':row.id,   'rectPeriod':this.rectPeriod[index],})}).then(({data})=>{if (data && data.code === 0) {this.$message({message: '操作成功',type: 'success',duration: 1500,onClose: () => {this.$set(this.showEdit,index,false)}})} else {this.$message.error(data.msg)}})},}
}

关键代码都在前两步,我写的好啰嗦啊,凑活看吧

vue+elementui实现可编辑表格相关推荐

  1. Vue - ElementUI中循环渲染表格,控制字段的显示与隐藏 v-if与v-for同时使用

    在Vue中使用v-for循环一个数组/对象时,如果再使用v-if,那么会提示使用计算属性(能正常使用),因为Vue中是不提倡v-for与v-if同时使用的. 在我的项目中也遇到了问题 不过翻看文档解决 ...

  2. vue element-ui动态横向统计表格

    表格结构 <el-table:data="AllData"style="width: 100%"><el-table-columnprop=& ...

  3. Vue + ElementUI el-table动态生成表格(表头含有中文、英文、数字等),表头宽度自适应实现

    表格html片段 <section class="w-full h-786 overflow-auto"><div class="right-table ...

  4. Vue+ElementUI纯前端技术实现对表格数据的增删改查

    Vue+ElementUI纯前端技术实现对表格数据的增删改查 页面展示效果 一.页面结构 分为三个部分 head body 以及script 一般我个人是在head中引入一些组件库 , 还有一些样式 ...

  5. Vue+element-ui实现表格数据渲染+分页

    Vue+element-ui实现表格数据渲染+分页 具体属性请看官方文档:Table 表格 这里给大家看一个比较不错的表格数据渲染的例子,也是我目前所写的项目中的一部分. 这里呢我们就不给大家说顶栏和 ...

  6. Handsontable VUE+element-ui +handsontable 实现Excel复制文本到项目表格列表(基于Elemenet+handsontable)

    @VUE封装handsontable(仿写Element样式)-重点查看使用方法 #Handsontable VUE+element-ui 实现Excel复制文本到项目表格列表(基于Elemenet) ...

  7. Vue+element-ui 实现表格的分页功能示例

    Vue+element-ui 实现表格的分页功能示例 template部分: <el-table:data="tempList":header-cell-style=&quo ...

  8. vue element项目常见实现表格内部可编辑功能

    目录 前言 正文 1.简单表格行内内部可编辑 2. 数据从后端取得表格行内可编辑 3.批量表格整体的可编辑 结语 前言 后台系统都是各种表格表单编辑,整理了下常见的几种实现表格编辑的方式,希望有用.使 ...

  9. ElementUI table组件,表格组件,单击单元格可编辑逻辑

    ElementUI table组件,表格组件,单击单元格可编辑逻辑 1.表格部分 <el-table:data="seatDataFilter"@cell-click=&qu ...

最新文章

  1. Eclipse将android 类编译为jar类库
  2. 34、Power Query-中国式排名
  3. Tomcat+Nginx+Memcached集群部署
  4. 《编写高质量代码改善JavaScript程序的188个建议》读书笔记
  5. [51单片机] EEPROM 24c02 [I2C代码封装-保存实现流水灯]
  6. android 字体竖直居中_问下弹性盒内不知道高度的时候想让字体垂直居中代码要怎么写...
  7. Bundling and Minification
  8. float类型转integer_【第3章:Java基础程序设计】_Java数据类型
  9. 创建一个1000w个随机浮点数的数组
  10. 安装 SQL Server Compact Edition 及 与PC 数据同步的部署
  11. R语言之导入数据源(二)
  12. 交换机常用命令及console口配置
  13. python scipy 计算黎曼ζ函数
  14. 冒泡排序(Bubble Sort)含gif动图
  15. 简单使用python进行图像打标
  16. Candence PCB Allegro④约束规则管理与布线
  17. w8系统桌面没有计算机图标,不见了win8系统桌面图标怎么办
  18. web攻防教学防黑客攻击,预防网站攻击
  19. 气象地图gis php代码,基于百度地图API实现自动气象站点信息显示
  20. Excel 使用小妙招之解决“##”显示问题

热门文章

  1. html 表格的边框颜色代码,html 表格细边框处理
  2. call、apply、bind函数详解
  3. 有关LOGO设计软件
  4. Android 大转盘 好用的示例
  5. Facebook如何击溃Myspace,Yahoo!和Google?(转载)
  6. 干货大总结!链报时空梭区块链高峰论坛圆满落幕
  7. django2.0 在安装mysqlclient 报错ERROR: Command errored out with exit status 1: python setup.py egg_info
  8. python三维数组转置_numpy.transpose对三维数组的转置方法
  9. JavaScript之本地存储使用
  10. Git - 时光机穿梭之管理修改