<el-tabs v-model="activeName" class="demo-tabs" @tab-change="scrollContainerEvent">
<el-tab-pane
:label="item.label"
:name="item.value"
v-for="(item, index) in tabPanes"
:key="index"
></el-tab-pane>
</el-tabs>
父页面
const scrollToPosition = (id: string) => {
permissionRef.value.scrollContainerEvent(id);
};
const cellClick = (row: any, column: any) => {
if (column.property === "name") {
const dataId = row.id;
scrollToPosition(dataId);
}
};
子组件
const scrollContainerEvent = (id: string) => {
const element = document.querySelector<HTMLElement>("[data-id='" + id + "']");
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}
};
defineExpose({ scrollContainerEvent });