el-table 可编辑列表

一、需求:
1、列表前两列的表头,可以进行点击
2、列表非前两列的表格项中,点击编辑图标可以进行编辑
3、列表非前两列的表格项中,编辑文本失去焦点,变为不可编辑状态

二、实现
1、html

<el-table :data="list1">

      <el-table-column prop="name" align="center">
        <template slot="header" slot-scope="scope">
          <el-button @click="clickColumn1(scope.column, scope.$index)">可点击触发事件--列1</el-button>
        </template>
        <template slot-scope="scope">{{scope.row.name}}</template>
      </el-table-column>
      
      <el-table-column prop="age" align="center">
        <template slot="header" slot-scope="scope">
          <el-button @click="clickColumn2(scope.column, scope.$index)">可点击触发事件--列2</el-button>
        </template>
        <template slot-scope="scope">{{scope.row.age}}</template>
      </el-table-column>
      
      <el-table-column label="可编辑信息1" width="300" prop="remark" align="center">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center">
            <el-input v-model="scope.row.remark1" :disabled="!scope.row.edit" @blur="blurColumn(scope.row, scope.$index)"></el-input>
            <span class="el-icon-edit" style="margin-left: 10px;" @click="editColumn(scope.row, scope.$index)"></span>
          </div>
        </template>
      </el-table-column>
      
      <el-table-column label="可编辑信息2" width="300" prop="remark" align="center">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center">
            <el-input v-model="scope.row.remark2" :disabled="!scope.row.edit" @blur="blurColumn(scope.row, scope.$index)"></el-input>
            <span class="el-icon-edit" style="margin-left: 10px;" @click="editColumn(scope.row, scope.$index)"></span>
          </div>
        </template>
      </el-table-column>
      
      <el-table-column label="可编辑信息3" width="300" prop="remark" align="center">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center">
            <el-input v-model="scope.row.remark3" :disabled="!scope.row.edit" @blur="blurColumn(scope.row, scope.$index)"></el-input>
            <span class="el-icon-edit" style="margin-left: 10px;" @click="editColumn(scope.row, scope.$index)"></span>
          </div>
        </template>
      </el-table-column>
      
      <el-table-column label="可编辑信息4" width="300" prop="remark" align="center">
        <template slot-scope="scope">
          <div style="display: flex; align-items: center">
            <el-input v-model="scope.row.remark4" :disabled="!scope.row.edit" @blur="blurColumn(scope.row, scope.$index)"></el-input>
            <span class="el-icon-edit" style="margin-left: 10px;" @click="editColumn(scope.row, scope.$index)"></span>
          </div>
        </template>
      </el-table-column>

</el-table>

2、js

export default{
	data(){
		return {
			 list1:[
				        {
				           name: 'bob',
				           age: 11,
				           remark1: 'remark1',
				           remark2: 'remark2',
				           remark3: 'remark3',
				           remark4: 'remark4',
				           edit: false
				         },
				         {
				           name: 'mary',
				           age: 22,
				           remark1: 'remark1',
				           remark2: 'remark2',
				           remark3: 'remark3',
				           remark4: 'remark4',
				           edit: false
				         },
			],
		}
	},
	methods: {
		// 可点击触发事件--列1
	     clickColumn1(column, index){
	        console.log(column);
	        console.log(index);
	        console.log(111);
	      },
	      // 可点击触发事件--列2
	      clickColumn2(column, index){
	        console.log(column);
	        console.log(index);
	        console.log(222);
	      },
	      // 编辑 column
	      editColumn(row, index){
	        console.log('editColumn');
	        this.$set(this.list1[index], 'edit', true)
	      },
	      // 取消编辑 column
	      blurColumn(row, index){
	        console.log('blurColumn');
	        this.$set(this.list1[index], 'edit', false)
	      },
	}
}

三、效果
在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值