el-table 中,使用 v-if 后表格列的次序错乱
...小于 1 分钟
el-table 中,使用 v-if 后表格列的次序错乱
背景
使用 el-table 组件,并且在列中使用了v-if指令,容易导致列的次序错乱。
解决的方法也很简单,只需要为每个el-table-column添加一个key属性即可。
<el-table stripe v-loading="loading" style="width: 100%;" :data="tableData" :height="height">
  <el-table-column type="index" fixed width="70" align="center" label="序号" :key="1" />
  <el-table-column
    v-if="USER_LV === 0"
    prop="subCompanyName"
    align="center"
    label="公司名称"
    width="150"
    key="2"
    :show-overflow-tooltip="true">
  </el-table-column>
  <el-table-column
    v-if="USER_LV !== 2"
    prop="projectName"
    align="center"
    label="项目名称"
    key="3"
    :show-overflow-tooltip="true">
  </el-table-column>
</el-table>