uniapp-外部view根据图片高度自适应,解决​uni-collapse 折叠面板,在折叠开的时候​和图片未加载出来高度不准确的问题

目录

图片未加载出来高度问题

uni-collapse 折叠面板 组件高度问题

注:我这里使用了自己封装获取节点信息 getCreateSelectorQueryNode() 方法 代码

图片未加载出来高度问题

<view id="box" :style="'height:' + boxH + 'px;'">
    <image id="img" :src="src" :mode="mode" @load="onLoadHandler"></image>
</view>

利用 image 图片加载完成执行的事件 onLoadHandler,获取当前图片最新的高度

const boxH = shallowRef(0)
const onLoadHandler = () => {
		nextTick(() => {
			getCreateSelectorQueryNode('#img').then(res => {
				boxH.value = res.height
			})
		})
	}

uni-collapse 折叠面板 组件高度问题

比如:uni-collapse 折叠面板 在折叠开的时候,myBox 组件中图片未加载出来高度不准确的问题

<uni-collapse :accordion="true">
		<uni-collapse-item :customH="customH">

                <template v-slot:title>
					<view>title</view>
				</template>
				
				<myBox id="myBox" " @load="load"/>
			
		</uni-collapse-item>
</uni-collapse>

 myBox 组件中的 image 加载完成后,传递事件给父组件,然后获取 myBox 的高度,赋给 uni-collapse 新高度

const customH= shallowRef(0)

const load = () => {
		nextTick(() => {
			getCreateSelectorQueryNode('#myBox').then(res => {
				customH.value = res.height
			})
		})
	}

在 uni-collapse 折叠面板  uni-collapse-item 组件中,利用传递过去 customH 新的高度,更改 uni-collapse-item__wrap 类名中的 动态行内样式

:style="{minHeight: (isOpen ? (customH ? customH : height) :0) +'px'}"

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

joshua king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值