问题描述:使用u-view组件u-collapse,动态渲染联系人数据时有时候会高度计算错误,多次请求后,折叠栏展示不全
解决方案:
1.给折叠栏加ref,利用change事件监听展开
<u-collapse v-for="(item,index) in personData" @change="handleOpenChange">
<u-collapse-item :title="item.deptName" :open="index==0" ref="collapseHeight">
<uni-table :border="false">
<uni-tr>
<uni-th width="130rpx" style="color:#1a3189;">负责人</uni-th>
<uni-th width="330rpx" style="color:#1a3189;">区域</uni-th>
<uni-th style=" color:#1a3189;">电话</uni-th>
</uni-tr>
<uni-tr v-for="(i,index1) in item.persons" :key="index1">
<uni-td style=" ">{{i.userName}}</uni-td>
<uni-td style=" ">{{i.areaName}} </uni-td>
<uni-td style="">
<a :href="'tel:' + i.phoneNumber">{{i.phoneNumber}}</a>
</uni-td>
</uni-tr>
</uni-table>
</u-collapse-item>
</u-collapse>
2.methods中加handleOpenChange函数,计算高度
发送完请求之后调用一下次函数
methods: {
// 计算折叠版高度
handleOpenChange() {
let long = this.$refs.collapseHeight.length;
setTimeout(() => {
for (let i = 0; i < long; i++) {
this.$refs.collapseHeight[i].queryRect();// 计算高度
}
}, 50)
},