vue + element table的树型表格的实现

我想要根据sonList这个字段来实现,但是不清楚js应该怎么绑定
这是我写的html部分,有很多错误 我拼凑的。。

<el-table
        :data="list"
        v-loading="listLoading"
        element-loading-text="Loading"
        fit
        highlight-current-row
        row-key="list.requireCode"
        border
        default-expand-all
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
         <el-table-column label="名称" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.requireName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="代码" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.requireCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="类型" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.requireType }}</span>
          </template>
        </el-table-column>
        <el-table-column label="字段名" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.fieldName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link :underline="false" @click="rowClick(scope.row)">
              <i class="el-icon-edit" />
            </el-link>
            <el-link
              :underline="false"
              @click.stop="deleteRequire(scope.$index, scope.row)"
            >
              <i class="el-icon-delete" />
            </el-link>
          </template>
        </el-table-column>
      </el-table>

这是其中的一条数据:
image.png

阅读 3.3k
1 个回答
<el-table
        :data="list"
        v-loading="listLoading"
        element-loading-text="Loading"
        fit
        highlight-current-row
        row-key="list.requireCode"
        border
        default-expand-all
        :data="sonList"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >

这里添加 :data="sonList"。建议亲好好看下element文档

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题