mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [table] fix absence of theadRef bug (#21454)
fix(components): [TableHeader] fix absence of theadRef bug
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
h,
|
||||
inject,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
reactive,
|
||||
ref,
|
||||
@@ -80,8 +81,9 @@ export default defineComponent({
|
||||
const saveIndexSelection = reactive(new Map())
|
||||
const theadRef = ref()
|
||||
|
||||
let delayId: ReturnType<typeof setTimeout> | undefined
|
||||
const updateFixedColumnStyle = () => {
|
||||
setTimeout(() => {
|
||||
delayId = setTimeout(() => {
|
||||
if (saveIndexSelection.size > 0) {
|
||||
saveIndexSelection.forEach((column, key) => {
|
||||
const el = theadRef.value.querySelector(
|
||||
@@ -98,6 +100,12 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
watch(saveIndexSelection, updateFixedColumnStyle)
|
||||
onBeforeUnmount(() => {
|
||||
if (delayId) {
|
||||
clearTimeout(delayId)
|
||||
delayId = undefined
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
// Need double await, because updateColumns is executed after nextTick for now
|
||||
|
||||
Reference in New Issue
Block a user