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

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

表格行内内部可编辑
数据从后台取得的表格行内可编辑
表格整体的可编辑
正文
1.简单表格行内内部可编辑
原理就是span 和 input 的切换显隐。

在这里插入图片描述
代码:

<template><div><el-table :data="tabledatas" border><el-table-column label="tab1"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.tab1"></el-input><span v-show="!scope.row.show">{{scope.row.tab1}}</span></template></el-table-column><el-table-column label="tab2"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.tab2"></el-input><span v-show="!scope.row.show">{{scope.row.tab2}}</span></template></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-button @click="scope.row.show =true">编辑</el-button><el-button @click="scope.row.show =false">保存</el-button></template></el-table-column></el-table></div>
</template>
<script>export default {data() {return {tabledatas: [{ tab1: '111', tab2: '2222',show:true},{ tab1: 'aaa', tab2: 'bbb' ,show:false},],}},}
</script>
  1. 数据从后端取得表格行内可编辑
    从后台取得的数据,可能没有show这个属性,所以在接收数据的时候操作一下,加这个属性,效果依然。但此时也会遇见保存时候需要把这个属性去掉,不影响传输正确数据。

代码:

<template><div><el-table :data="tabledatas" border><el-table-column type="selection"></el-table-column><el-table-column label="tab1"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.tab1"></el-input><span v-show="!scope.row.show">{{scope.row.tab1}}</span></template></el-table-column><el-table-column label="tab2"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.tab2"></el-input><span v-show="!scope.row.show">{{scope.row.tab2}}</span></template></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-button @click="scope.row.show =true">编辑</el-button><el-button @click="scope.row.show =false">保存</el-button></template></el-table-column></el-table></div>
</template>
<script>export default {data() {return {tabledatas: [],}},created() {// 发请求去后台拿数据,如果有api,就正常请求,//我这里是demo,就简单给list赋值了,原理一样。// getlistApi().then(res => {// let list = res.data.listlet list = [{ tab1: 'tast2', tab2: 'tast333' },{ tab1: 'aaa', tab2: 'bbb' },]list.forEach(element => {element["show"] = false});this.tabledatas = list// })},}
</script>

3.批量表格整体的可编辑
效果图:
在这里插入图片描述
代码:

<template><div><el-button @click="show =true">编辑</el-button><el-button @click="show =false">提交</el-button><el-table :data="tabledatas" border><el-table-column label="tab1"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="show" v-model="scope.row.tab1"></el-input><span v-show="!show">{{scope.row.tab1}}</span></template></el-table-column><el-table-column label="tab2"><template slot-scope="scope"><el-input placeholder="请输入内容" v-show="show" v-model="scope.row.tab2"></el-input><span v-show="!show">{{scope.row.tab2}}</span></template></el-table-column></el-table></div>
</template>
<script>export default {data() {return {tabledatas: [{ tab1: '111', tab2: '2222' },{ tab1: 'aaa', tab2: 'bbb'},],show:false}},}
</script>

结语
这是编辑保存功能,下篇顺便写一下行内和批量删除和增加行的功能吧~
附:vue+element的表格最优实现单条和批量修改、保存、复制、删除、新增、提交数据功能

如果本文对你有帮助的话,请给我点赞打call哦~o( ̄▽ ̄)do
有其他问题留言 over~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/406555.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

tar

tar命令是Unix的一个shell命令&#xff0c;该命令可在为多个制定文件创建一个档案文件&#xff0c;也可以从一个档案文件中解压缩出文件。tar档案文件的扩展名为“.tar”。tar包中的文件并不是压缩文件&#xff0c;而是所有文件集合成的一个文件。 tar这个名字源自在磁带上备份…

Yii2.0 技巧总结

View部分 1. 使用ActiveField中的hint生成提示文字 <? $form->field($model, freightAddedFee)->textInput()->hint(大于0的整数) ?> 2. 文本框添加placeholder属性&#xff0c;其实这个本来就是html5带的属性。 <? $form->field($model, mobile, $inp…

React开发(157):一级直接用getFieldDecorator

<Row gutter{12}><Col span{12}><Form.Item label"省/市/区">{getFieldDecorator(proviceValue, {initialValue: proviceValue,rules: [{ required: true, message: 公司人数不能为空 }],})(<CascaderfieldNames{fieldNames}options{options}on…

【JavaScript】appendChild一个的注意点之会删除原dom树节点

最近在研究学习vue原理&#xff0c;其中使用createDocumentFragment()方法&#xff0c;是用来创建一个虚拟的节点对象&#xff0c;那问题来了&#xff0c;创建了虚拟dom树&#xff0c;且最后只渲染了虚拟dom树里面的节点&#xff0c;那原dom树的节点去哪里了&#xff0c;查阅了…

正则表达式图书

From: http://www.usidcbbs.com/read-htm-tid-1457-page-2.html 网文 vs 书藉 只要是知道“正则”这个词的&#xff0c;上网搜集个把资料&#xff0c;应该就不是问题吧。我获得正则消息的网絡渠道有这样几个&#xff0c;以质量从高到低排序&#xff1a;dilicious标签&#xff0…

Spring.NET学习笔记12——面向切面编程(基础篇) Level 300

AOP即面向切面编程(Aspect Oriented Programming的缩写)&#xff0c;是OOP(面向对象编程)的一种延续形式。是通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术&#xff0c;它从一个不同于OOP的角度来看待程序的结构&#xff1a;OOP将…

React开发(158):ant design级联回显 直接传入数组

ReactDOM.render(<CascaderdefaultValue{[zhejiang, hangzhou, xihu]}options{options}onChange{onChange}/>,mountNode, );

vue-cli3使用svg图标的详细步骤

1.安装依赖 npm install svg-sprite-loader -D2.在vue.config.js里添加配置 module.exports{chainWebpack: config > {const svgRule config.module.rule("svg"); svgRule.uses.clear();svgRule.use("svg-sprite-loader").loader("svg-sprite…

网络工程师的忠告

诸位&#xff0c;咱当网络工程师也是几年了&#xff0c;不算有出息&#xff0c;环顾四周&#xff0c;也没有看见几个有出息的&#xff01;回顾工程师生涯&#xff0c;感慨万千&#xff0c;愿意讲几句掏心窝子的话&#xff0c;也算给咱们师弟师妹们提个醒&#xff0c;希望他们比…

python模拟登陆163邮箱并获取通讯录

From: http://hi.baidu.com/fc_lamp/blog/item/2466d1096fcc532de8248839.html python模拟登陆163邮箱并获取通讯录 #-*- coding:UTF-8 -*-import urllib,urllib2,cookielibimport xml.etree.ElementTree as etree #xml解析类class Login163:#伪装browserheader {User-Agent:…

【BZOJ】【3850】ZCC Loves Codefires

贪心 就跟NOIP2012国王游戏差不多&#xff0c;考虑交换相邻两题的位置&#xff0c;对其他题是毫无影响的&#xff0c;然后看两题顺序先后哪个更优。sort即可。 WA了一次的原因&#xff1a;虽然ans开的是long long&#xff0c;但是在这一句:anstime*a[i].k;时&#xff0c;还是需…

Element-UI中关于table表格的那些骚操作

最近的项目中使用到element-ui组件库&#xff0c;由于做的是后台管理系统&#xff0c;所以经常需要操作表格&#xff0c;编辑样式的过程中遇到一些问题&#xff0c;官网针对table给出了很多的api&#xff0c;自己可以自定义&#xff0c;基本能满足产品需求&#xff0c;但是没有…

讯闪菜单密码去除方法

网上有很多关于讯闪菜单密码去除或补丁软件&#xff0c;但都没有把原理说出来&#xff0c;下面介绍方法&#xff1a;打开&#xff1a;讯闪目录\data\ClientCfg.ini查找&#xff1a;分类辅助d41d8cd98f00b204e9800998ecf8427e把分类辅助替换为&#xff1a;d41d8cd98f00b204e9800…

详细介绍 Qt Creator 快捷捷应用

From: http://www.zhujiangroad.com/program/Symbian/25211.html Qt Creator 快捷捷应用是本文要介绍的内容 。以前经常用VSQT的方式来学习QT&#xff0c;VS确实挺强大&#xff0c;不过每次编译Qt&#xff0c;太浪费时间&#xff0c;而且如果重装系统或者VS都必须重新编译&…

asp IIS部署An error occurred on the server when processing the URL错误提示解决

An error occurred on the server when processing the URL. Please contact the system administrator.If you are the system administrator please click here to find out more about this error.其实这是 IIS7 对 ASP 程序发送的一个脚本错误消息&#xff0c;只要是程序中…

修饰符.lazy .number .trim

1、lazy v-model 在每次 input 事件触发后将输入框的值与数据进行同步,也就是在失去焦点或者按下回车键时才更新 <template><div><p>.lazy修饰符</p><input type"text" v-model.lazy"val"><p>{{ val }}</p><…

使用Phar来打包发布PHP程序

简单来说&#xff0c;Phar就是把Java界的jar概念移植到了PHP界。 Phar可以将一组PHP文件进行打包&#xff0c;还可以创建默认执行的stub&#xff08;或者叫做 bootstrap loader&#xff09;&#xff0c;Phar可以选择是否进行压缩&#xff0c;可选gzip和bzip2格式。 下面举例说明…