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)
		},
相关推荐
前端Hardy43 分钟前
别再忽略 Promise 拒绝了!你的 Node.js 服务正在“静默自杀”
前端·javascript·面试
前端Hardy1 小时前
别再被setTimeout闭包坑了!90% 的人都写错过这个经典循环
前端·javascript·vue.js
小林coding1 小时前
专为程序员打造的简历模版来啦!覆盖前端、后端、测开、大模型等专业简历
前端·后端
前端Hardy1 小时前
你的 Vue 组件正在偷偷吃掉内存!5 个常见的内存泄漏陷阱与修复方案
前端·javascript·面试
RaidenLiu1 小时前
Flutter Platform Channel 底层架构解析 —— 从 BinaryMessenger 到跨平台消息通信机制
前端·flutter·前端框架
bluceli1 小时前
CSS容器查询:响应式设计的新范式
前端·css
Tapir1 小时前
被 Karpathy 下场推荐的 NanoClaw 是什么来头
前端·后端·github
前端人类学1 小时前
深入解析JavaScript中的null与undefined:区别、用法及判断技巧
前端·javascript
ssshooter2 小时前
Tauri 项目实践:客户端与 Web 端的授权登录实现方案
前端·后端·rust
兆子龙2 小时前
【React】19 深度解析:掌握新一代 React 特性
前端·架构