Vue element table点击单元格可编辑

2 篇文章 0 订阅
本文介绍了如何在Vue的el-table组件中实现点击单元格时动态显示输入框并保存用户输入。通过`cell-click`事件和`cell-class-name`属性,结合v-if和v-model,实现实时交互。关键代码展示了表格初始化、输入框处理和行列索引管理的方法。
摘要由CSDN通过智能技术生成

1、

<el-table :data="tableData" @cell-click="cellClick"
			:cell-class-name="getRowColumn">
	<el-table-column prop="note" align="center" label="列1" >
		<template  slot-scope="scope">
			<el-input v-if="scope.row.index==clickCellRowIndex && scope.column.index==clickCellColumnIndex" size="small" v-model="scope.row.note" @blur="inputBlur" 
            				placeholder="请输入">
			</el-input>
			<span v-else>{{scope.row.note}}</span>
		</template>
	</el-table-column>
</el-table>

2、

data(){
	return {
		clickCellRowIndex:null,//用于判断点击是哪行
		clickCellColumnIndex:null,//用于判断点击是哪列
	}
}

3、

methods{
	//输入框 失去焦点
	inputBlur(index,row){
		this.clickCellRowIndex = null
		this.clickCellColumnIndex = null

	},
	//点击cell
	cellClick(row,column,cell,event){
		this.clickCellRowIndex = row.index
		this.clickCellColumnIndex = column.index

	},
	//table初始化的时候给行和列 赋index
	getRowColumn({row,column,rowIndex,columnIndex}){
		row.index = rowIndex
		column.index = columnIndex
	},
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值