vue+elementUI实现指定列的单元格可编辑

template中的代码如下:

html 复制代码
<div v-if="(item.label === '高压侧' || item.label === '低压侧')&&coloumnHeader.label === '单柱片数'">
							<div class="editableCell">
								<div v-if="item.label === '高压侧'" @dblclick="changeValue(scope.$index, scope.row,'high')">
									<span v-if="!scope.row.highEdit">{{scope.row[item.prop]}}</span>
									<el-input 
										v-model="scope.row[item.prop]" 
										v-else="scope.row.highEdit" 
										size="mini" 
										@blur.native.capture="valueBlur(scope.$index, scope.row, 'high')" 
										v-focus></el-input>
								</div>
								<div v-else @dblclick="changeValue(scope.$index, scope.row,'low')">
									<span v-if="!scope.row.lowEdit">{{scope.row[item.prop]}}</span>
									<el-input 
										v-model="scope.row[item.prop]" 
										v-else="scope.row.lowEdit" 
										size="mini" 
										@blur.native.capture="valueBlur(scope.$index, scope.row, 'low')"
										v-focus></el-input>
								</div>			
							</div>
						</div>

js代码如下:

javascript 复制代码
		/**
		 * 高压侧低压侧列双击可输入值
		 * @param {Number} index 行索引
		 * @param {Object} rowData 行数据
		 * @param {String} type 高低压侧类型
		 */
		 changeValue(index,rowData, type){
			if(type === 'high'){
				// 数据更新,视图更新
				if(Object.keys(this.updateTableData[index]).indexOf("highEdit") === -1){
					// 还没编辑过的添加编辑属性
					this.$set(this.updateTableData, index,{highEdit:true,...this.updateTableData[index]});
				}else{
					// 已经编辑过的,更改编辑属性
					this.$set(this.updateTableData[index], "highEdit", true);
				}				
			}else if(type === 'low'){
				if(Object.keys(this.updateTableData[index]).indexOf("lowEdit") === -1){
					this.$set(this.updateTableData, index,{lowEdit:true,...this.updateTableData[index]});
				}else{
					this.$set(this.updateTableData[index], "lowEdit", true);
				}
				
			}
		},
		/**
		 * 输入框失去焦点时触发
		 * @param {Number} index 行索引
		 * @param {Object} rowData 行数据
		 * @param {String} type 高低压侧类型
		 */
		 valueBlur(index,rowData, type){
			// 数据更新,视图更新
			if(type === "high"){
				this.$set(this.updateTableData[index], "highEdit", false);
			}else{
				this.$set(this.updateTableData[index], "lowEdit", false);
			}
			console.log(this.updateTableData)
		},
相关推荐
椰子皮啊3 小时前
400行Node.js搞定mediasoup信令转换:一次跨语言"表白"实录
前端·架构
果然_4 小时前
告别混淆!Git 多账号按域名/目录自动切换身份的终极指南
前端
Wect4 小时前
React Scheduler & Lane 详解
前端·react.js·面试
myNameGL4 小时前
ArkTs核心语法
前端·javascript·vue.js
重庆穿山甲4 小时前
从零到精通:OpenClaw完整生命周期指南
前端·后端·架构
浏览器API调用工程师_Taylor4 小时前
web逆向之小红书无水印图片提取工具
前端·javascript·逆向
程序员阿峰4 小时前
【JavaScript面试题-作用域与闭包】什么是闭包?闭包在实际开发中有什么应用和潜在问题(如内存泄漏)?
前端·面试
yuki_uix4 小时前
性能指标与优化:从 Core Web Vitals 到实战
前端·javascript
简单不容易4 小时前
vue一次解决监听H5软键盘弹出和收起的兼容问题
javascript·vue.js
Oneslide4 小时前
flex布局实现水平和垂直对齐
前端