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

template中的代码如下:

<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代码如下:

		/**
		 * 高压侧低压侧列双击可输入值
		 * @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)
		},
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值