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)
		},
相关推荐
foundbug9993 分钟前
Modbus协议C语言实现(易于移植版本)
java·c语言·前端
Luna-player3 分钟前
在前端中list.map的用法
前端·数据结构·list
用户47949283569158 分钟前
面试官问 React Fiber,这一篇文章就够了
前端·javascript·react.js
LYFlied20 分钟前
【一句话概述】Webpack、Vite、Rollup 核心区别
前端·webpack·node.js·rollup·vite·打包·一句话概述
用户8417948145624 分钟前
vxe-table 实现滚动加载数据,无限加载数据教程
vue.js
reddingtons31 分钟前
PS 参考图像:线稿上色太慢?AI 3秒“喂”出精细厚涂
前端·人工智能·游戏·ui·aigc·游戏策划·游戏美术
一水鉴天33 分钟前
整体设计 定稿 之23+ dashboard.html 增加三层次动态记录体系仪表盘 之2 程序 (Q199 之2) (codebuddy)
开发语言·前端·javascript
刘发财35 分钟前
前端一行代码生成数千页PDF,dompdf.js新增分页功能
前端·typescript·开源
_请输入用户名39 分钟前
Vue 3 源码项目结构详解
前端·vue.js
前端无涯1 小时前
Vue3---(2)setup
vue.js