需求:父页打开弹窗,弹窗子页显示数据列表。父页存在筛选条件时,子页打开直接滚动至对应条目,并高亮。
首先列表dom是通过表格数据循环所得,要做滚动跟随,必须设置态id;然后利用元素id选择器,自动滚动到对应dom位置;高亮利用:class属性和循环index来完成:
<div ref="barList">
<div v-for="(item, index) in tableData" :key="index"
class="bar-item"
:class="{'isActive': chartActiveNum===index}"
:id="'barlist-row-'+index"
@click="barRowClick(item,index)"
>
</div>
</div>
methods: {
// 列表滚动跟随至选中的行
detailScrollFollow(prefix,ids) {
this.$el.querySelector( prefix + ids ).scrollIntoView();
},
// 引用方法
tableChartChange(ids) {
this.tableChartType = ids; // 1表格 2图表
if ( this.tableChartType === 1 ) {
// 滚动条跟随选中行
if ( this.$refs.barList ) {
this.$nextTick(function () {
this.detailScrollFollow("#barlist-row-",this.chartActiveNum);
});
}
}
}
}
另一子页弹窗,待父页清空筛选条件或子页切换tab后,需清空滚动内容,并置顶滚动条:
// 置顶单位详情滚动条
detailScrollTop() {
if ( this.$refs.unitList ) {
this.$nextTick(function () {
this.$refs.unitList.scrollTop = 0;
});
}
}