element ui中树形表格expand-row-keys为什么失效

设置expand-row-keys属性之后,在methods修改后,不生效

img


img


这个主要是实现树形表格每次只能展开一行

参考如下代码

<template>
  <el-table
    :data="tableData"
    row-key="id"
    :expand-row-keys="expandKeys"
    @expand-change="expandChange"
    style="width: 100%">
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="商品厂商">
            <span>{{ props.row.vendor}}</span>
          </el-form-item>
        </el-form>
      </template>
    </el-table-column>
    <el-table-column
      label="商品 ID"
      prop="id">
    </el-table-column>
    <el-table-column
      label="商品名称"
      prop="name">
    </el-table-column>
    <el-table-column
      label="描述"
      prop="desc">
    </el-table-column>
  </el-table>
</template>

<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

<script>
  export default {
    data() {
      return {
      form:{
          id: '',
          name: '',
          desc: '',
          vendor:''
        },
          expandKeys:[],
        tableData: []
      }
    },
    methods:{
        expandChange(row,expandRows){
        if(this.expandKeys.indexOf(row.id) >= 0){
            //首期当前行
            this.expandKeys.shift()
            return;
            }
            //恢复默认值
            let _this = this
            _this.checklist = {}
            const data = {
            "id": row.id,
            }
            axios
            .post(maintainFront.api_url + "getInfo", JSON.stringify(data))
            .then(res => {
                _this.checklist = res.data
                if (JSON.stringify(_this.checklist) == '{}'){
                    _this.expandKeys.shift()
                    _this.expandKeys.push(row.id)
                    altert("信息为空")
                }else{
                    row["vendor"] = _this.checklist["vendor"]
                    _this.expandKeys.shift()
                    _this.expandKeys.push(row.id)
                }
                })
                .catch(function (error){
                    console.log(error);
                });
                if (expandRows.length >1){
                    expandRows.shift()
                }
            }
        }
  }
</script>