修复 table header 与 body 的滚动同步问题
This commit is contained in:
parent
71e56f3fe7
commit
0d28395610
@ -12,6 +12,7 @@ import {
|
|||||||
defineProps,
|
defineProps,
|
||||||
withDefaults,
|
withDefaults,
|
||||||
defineEmits,
|
defineEmits,
|
||||||
|
onMounted,
|
||||||
} from "vue";
|
} from "vue";
|
||||||
import { Recordable } from "../../types";
|
import { Recordable } from "../../types";
|
||||||
import { guid } from "../../utils/guidUtil";
|
import { guid } from "../../utils/guidUtil";
|
||||||
@ -109,6 +110,16 @@ const print = function () {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
document.body.innerHTML = oldContent;
|
document.body.innerHTML = oldContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tableHeader = ref<HTMLElement | null>(null);
|
||||||
|
let tableBody = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
tableBody.value?.addEventListener('scroll', () => {
|
||||||
|
tableHeader.value!.scrollLeft = tableBody.value?.scrollLeft || 0;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -152,7 +163,7 @@ const print = function () {
|
|||||||
|
|
||||||
<div class="layui-table-box">
|
<div class="layui-table-box">
|
||||||
<!-- 表格头部 -->
|
<!-- 表格头部 -->
|
||||||
<div class="layui-table-header">
|
<div class="layui-table-header" ref="tableHeader">
|
||||||
<table class="layui-table" :lay-size="size">
|
<table class="layui-table" :lay-size="size">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -181,7 +192,7 @@ const print = function () {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<!-- 表格数据 -->
|
<!-- 表格数据 -->
|
||||||
<div class="layui-table-body layui-table-main">
|
<div class="layui-table-body layui-table-main" ref="tableBody">
|
||||||
<table class="layui-table" :lay-size="size">
|
<table class="layui-table" :lay-size="size">
|
||||||
<tbody>
|
<tbody>
|
||||||
<template v-for="data in dataSource" :key="data">
|
<template v-for="data in dataSource" :key="data">
|
||||||
|
Loading…
Reference in New Issue
Block a user