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)
		},
相关推荐
HelloRevit4 分钟前
npm install 版本过高引发错误,请添加 --legacy-peer-deps
前端·npm·node.js
工九度6 分钟前
2025前端社招最新面试题汇总- 场景题篇
前端·javascript
AronTing6 分钟前
状态模式:有限状态机在电商订单系统中的设计与实现
前端·设计模式·面试
这可不简单7 分钟前
git push 受阻,原是未拉取代码惹的祸
前端·git·面试
啊吧啊吧曾小白10 分钟前
封装 downloadFile 函数,从服务器下载文件
前端·javascript·面试
左言12 分钟前
PYLSP 桥接 MONACO
前端
工业互联网专业19 分钟前
基于springboot+vue的数码产品抢购系统
java·vue.js·spring boot·毕业设计·源码·课程设计·数码产品抢购系统
Data_Adventure24 分钟前
使用CLINE快速生成一个3D展厅
vue.js·three.js·cline
Danny_FD27 分钟前
前端BFC详解:从基础到深入的全面解读
前端
临枫38836 分钟前
网页图像优化:现代格式与响应式技巧
前端