一. 需求
页面表格数据加载完成之后
计算一下需要滚动的高度
表格自动滚动
二. code
1. 给table加上ref
<el-table ref="tableRef" :data="tableData">...</el-table>
2. 使用nextTick在表格渲染完之后计算高度滚动
import { ref, nextTick } from 'vue'
const tableRefRanking = ref(null);
const tableData = ref([])
const getTableData = async () => {
isLoading.value = true
await xxApi({}).then((res) => {xxx})
}
nextTick(async () => {
await getTableData()
const rowIndex = tableData.value.findIndex(item => { return item.changeColor == true })
const yScroll = 36 * rowIndex
tableRef.value.setScrollTop(yScroll);
})