Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<el-table>进行表格循环的时候搭配 <el-input>组件进行编辑表格操作例如开启了 :autofocus="true"会导致第一次进入页面启用编辑状态后,导致表格错版 #23018

Open
laohan6 opened this issue Jan 2, 2025 · 0 comments

Comments

@laohan6
Copy link

laohan6 commented Jan 2, 2025

下面是触发bug的表格代码:

    <el-table-column
      v-for="(item,index) in tableTitleTree"
      :key="item.key"
      :label="item.label"
      align="center"
      min-width="200"
      :fixed="spanMethod ? ( index === 0 || index === 1) ? 'left':false : index === 0 ? 'left':false "
    >
      <el-table-column
        :label="item.list[0].label"
        :prop="`${item.list[0].key}`"
        align="center"
        min-width="200"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-input
            v-if="(item.list[0].type === 3  && scope.row.type === 1 && hasPermissionToEdit ) &&  isEditStatus"
            v-model.trim="scope.row[item.list[0].key]"
                 :autofocus="true"
            placeholder="请输入"
          />
          <span v-else>{{ scope.row[item.list[0].key] }}</span>
        </template>
      </el-table-column>

      <el-table-column
        v-for="Sitem in item.list.slice(1)"
        :key="Sitem.key"
        :prop="`${Sitem.key}`"
        :label="Sitem.label"
        align="center"
        min-width="200"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-input
            v-if="(Sitem.type === 3  && scope.row.type === 1 && hasPermissionToEdit ) &&  isEditStatus"
            v-model.trim="scope.row[Sitem.key]"
            :autofocus="true"
            placeholder="请输入"
          />
          <span v-else>{{ scope.row[Sitem.key]}}</span>
        </template>
      </el-table-column>
    </el-table-column>
  </el-table>

如果 :autofocus="true"那么在第一次进入页面时,进入编辑状态后会导致输入框的所在表格移位到其他表格中,导致页面单元格错乱,但是再进行一次浏览器刷新后,再进入编辑状态后输入框就恢复正常了。
formData: {
handler (newVal) {
const { tableData, tableTitle, tableTitleTree } = newVal
if (tableData || tableTitle) {
this.tableTitle = tableTitle.map((item) => {
return {
...item,
key: item.key.toString(),
}
})
this.tableData = JSON.parse(JSON.stringify(tableData))
this.tableTitleTree = JSON.parse(JSON.stringify(tableTitleTree))
this.changedData = JSON.parse(JSON.stringify(tableData))
}
},
deep: true,
immediate: true,
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant