1.HTML部分

  <tr v-for="(item,index) in customerVisitList2" :key="index">
<td class="customerName"><div class="divEdit" contenteditable="true" @blur="blurFunc($event,2,index,'customerName')">{{customerVisitList2[index].customerName}}</div></td>
<td class="visitTime"><div class="divEdit" contenteditable="true" @blur="blurFunc($event,2,index,'visitTime')">{{customerVisitList2[index].visitTime}}</div></td>
<td class="visitDesc"><div class="divEdit" contenteditable="true" @blur="blurFunc($event,2,index,'visitDesc')">{{customerVisitList2[index].visitDesc}}</div></td>
<td class="operation textAlignCenter"><div class="divEdit"><span class="iconfont icon-shanchu hoverStyle" @click="removeCustomerVisit(2,index)"></span></div></td>
</tr>

2.JS部分

        blurFunc(e,type,index,name){
       //失去焦点实现双向数据绑定
let content = e.target.innerText
e.target.innerText = ''
if(type === 1){
this.customerVisitList1[index][name] = content
}else{
this.customerVisitList2[index][name] = content
}
e.target.innerText = content
},
addCustomerVisit(type){
        //添加行
let index
if(type === 1){
this.customerVisitList1.push({customerType: 'oldCustomer',customerName:'',visitTime:'',visitDesc:''})
}else{
this.customerVisitList2.push({customerType: 'newCustomer',customerName:'',visitTime:'',visitDesc:''})
}
},
removeCustomerVisit(type,index){
//移除行
if(type === 1){
console.log(this.customerVisitList1)
this.customerVisitList1.splice(index,1)
}else{
console.log(this.customerVisitList2)
this.customerVisitList2.splice(index,1)
}
},

3.css部分(stylus)

.divEdit{
outline: none
}
.textAlignCenter{
text-align: center
}
.listTable{
padding 4px 10px 4px 4px
font-size 11px
width 100%
td,th{
padding-left 4px
line-height 24px
width 100%
}
.customerName{
width 150px
}
.visitTime{
width 120px
}
.visitDesc{
width auto
}
.operation{
width 34px
}
}

vue中用div的contenteditable属性实现v-for遍历,双向数据绑定的动态表格编辑的更多相关文章

  1. 使用div 的 contenteditable属性,实现输入编辑,输入 "#" 出现下拉选择

    文章原文:https://www.cnblogs.com/yalong/p/11883585.html 演示效果如下:   具体代码可以看 https://github.com/YalongYan/e ...

  2. Vue学习之--------Vue中收集表单数据(使用v-model 实现双向数据绑定、代码实现)(2022/7/18)

    文章目录 1.Vue中实现表单数据的收集 1.1 基础知识 1.2 代码实例 1.3 测试效果 1.4 额外插一嘴 1.Vue中实现表单数据的收集 1.1 基础知识 表单中常用的标签:input(输入 ...

  3. html元素contenteditable属性如何定位光标和设置光标

    最近在山寨一款网页微信的产品,对于div用contenteditable属性做的编辑框有不少心得,希望可以帮到入坑的同学. 废话不多说了,我们先来理解一下HTML的光标对象是如何工作的,后面我会贴完整 ...

  4. angular,vue,react的基本语法—双向数据绑定、条件渲染、列表渲染、angular小案例

    基本语法: 1.双向数据绑定 vue 指令:v-model="msg" react constructor(){ this.state{ msg:"双向数据绑定" ...

  5. contenteditable属性让div也可以当做输入框

    你知道div也可以当做输入框么? H5的全局属性contenteditable,带有contenteditable属性的div而不是input或者textarea来作为输入框(div可以根据内容自动调 ...

  6. 关于 div 的 contenteditable 使用,placeholder 和 复制图片显示并上传,按住 enter+ctrl 内容换行

    当使用文本编辑的时候,首先会使用 textarea ,但是,这个里面不能加入其它标签,也就是不能富文本化. 于是可以使用 contenteditable 就是给 div 加上该属性.就变得丰富起来.使 ...

  7. Vue中用props给data赋初始值遇到的问题解决

    Vue中用props给data赋初始值遇到的问题解决 更新时间:2018年11月27日 10:09:14   作者:yuyongyu    我要评论   这篇文章主要介绍了Vue中用props给dat ...

  8. contentEditable属性设置是否可编辑元素的内容

    在HTML5中在标签新添加了一个属性contentEditable可以设置标签内的内容是否可以编辑: 设置contenteditable="true"标签内的元素(内容)可以编辑 ...

  9. contenteditable 属性

    定义和用法 contenteditable 属性规定是否可编辑元素的内容. 语法 <element contenteditable="value"> 属性值 值 描述 ...

随机推荐

  1. Delphi下Treeview控件基于节点编号的访问

    有时我们需要保存和重建treeview控件,本文提供一种方法,通过以树结构节点的编号访问树结构,该控件主要提供的方法如下:      function GetGlobeNumCode(inNode:T ...

  2. Newton法(牛顿法 Newton Method)

               1.牛顿法应用范围                          牛顿法主要有两个应用方向:1.目标函数最优化求解.例:已知 f(x)的表达形式,,求 ,及g(x)取最小值时 ...

  3. 用Python做一个简单的小游戏

    学习总是枯燥的,对于Python小白的我来讲,更是乏味的.为了提高学习的兴趣,今天我就来写一个小程序练练手. 数字猜谜游戏相信大家都不陌生,A给出最小值最大值,B写一个该范围内的数,A猜测写下的是多少 ...

  4. 【MM系列】在SAP里查看数据的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]在SAP里查看数据的方法   前言部 ...

  5. vue input 循环渲染问题

    <li> <span>下属区县:</span> <div class="quxianList" v-for="(qx,index ...

  6. 使用Apache服务部署网站(基于IP,域名,端口)

    本篇主要学习Apache网站服务程序的基本部署,基于IP地址.主机名(域名).端口号的虚拟主机功能. 1.基于IP地址 首先我们需要在虚拟机中线安装Apache服务程序,Apache服务程序的软件包名 ...

  7. php $_SERVER['HTTP_REFERER']详解

    php $_SERVER['HTTP_REFERER']详解 ceshia.php <pre>echo '<a href="ceshib.php">cesh ...

  8. 登陆Linux服务器时触发邮件提醒

    目前,客户只能在发现数据或者虚拟机被恶意侵入或者用户的误操作导致了数据的丢失之后,采取善后的手段,但是并没法做到提前的预警.那么通过 PAM 模块,就可以实现用户登录及获取root 权限时,通过邮件的 ...

  9. Java基础---Java 开发工具IntelliJ IDEA 快捷操作

    IDE中快捷编写函数的方法 public static void main(String[] args) ===> psvm System.out.println(); ====> sou ...

  10. python中的 __inti__ 和 __new__ 方法的区别

    这个要从Python的面向对象实例化的过程说起 类名() 之后,开辟一块内存空间,然后调用__init__把空间的内存地址作为self的参数传递到函数的内部,所有和self有关的参数,属性都会和sel ...