vue中可编辑树状表格

vue中可编辑树状表格

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

html代码

 <template>
	<el-table
        :data="datatree"
        row-key="id"
        :tree-props="{children: 'children'}"
      >
        <el-table-column label="姓名" border>
                <template slot-scope="scope">
                    <el-input placeholder="请输入内容" v-show="scope.row.show" v-model="scope.row.label"></el-input>
                    <span v-show="!scope.row.show">{{scope.row.label}}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button @click="scope.row.show =true" >编辑</el-button>
                    <el-button @click="scope.row.show =false">保存</el-button>
                </template>
            </el-table-column>
      </el-table>
 </template>

js代码

<script>
export default {
	data(){
    	return {
    	datatree: [{
          id: 1,
          label: '水果',
          show:false,
          children: [{
            id: 4,
            label: '苹果',
            show:false,
            children: [{
              id: 9,
              label: '苹果皮',
              show:false
            }, {
              id: 10,
              label: '苹果仔',
              show:false
            }]
          }]
        }, {
          id: 2,
          label: '蔬菜',
          show:false,
          children: [{
            id: 5,
            label: '青菜',
            show:false
          }, {
            id: 6,
            label: '土豆',
            show:false
          }]
        }, {
          id: 3,
          label: '饮料',
          show:false,
          children: [{
            id: 7,
            label: '冰红茶',
            show:false
          }, {
            id: 8,
            label: '酷儿',
            show:false
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label',
          show:'show'
        }
    }
  }
}

嫌input框太大自己设置一下

在这里插入图片描述
一个简单的可编辑树状表格就出现了
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值