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)
		},
相关推荐
前端啵啵猪4 分钟前
useCallback 和 useMemo,什么时候用才是有效的?
前端·react.js
计算机学姐8 分钟前
基于Python的旅游数据分析可视化系统【2026最新】
vue.js·后端·python·数据分析·django·flask·旅游
星哥说事15 分钟前
跨平台开源笔记神器,用DeepSeek写笔记 , 效率翻倍
前端
喜欢你,还有大家43 分钟前
FTP文件传输服务
linux·运维·服务器·前端
该用户已不存在1 小时前
你没有听说过的7个Windows开发必备工具
前端·windows·后端
Bi1 小时前
Dokploy安装和部署项目流程
运维·前端
普通网友1 小时前
前端安全攻防:XSS, CSRF 等防范与检测
前端·安全·xss
携欢1 小时前
PortSwigger靶场之Reflected XSS into attribute with angle brackets HTML-encoded通关秘籍
前端·xss
小爱同学_1 小时前
React知识:useState和useRef的使用
前端·react.js
再学一点就睡1 小时前
双 Token 认证机制:从原理到实践的完整实现
前端·javascript·后端