亲测可用
<template>
<view>
{{items[current].height}}
<swiper class="swiper" @change="change" :style="{height: items[current].height + 'px'}">
<swiper-item>
<view class="swiper-item">
<view class="bgwhite mt16 p16" v-for="d in 4" :key="d">{{d}}</view>
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
<view class="bgwhite mt16 p16" v-for="d in 20" :key="d">{{d}}</view>
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
<view class="bgwhite mt16 p16" v-for="d in 10" :key="d">{{d}}</view>
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
current: 0,
items: []
}
},
mounted() {
uni.createSelectorQuery().selectAll('.swiper-item').boundingClientRect(data => this.items = data).exec()
},
methods: {
change(e) {
this.current = e.detail.current
}
}
}
</script>
4 个回复
Trust - 少说废话
JS 计算后设置 style
1***@qq.com
我计算后在浏览器正常,真机不行
n***@163.com
还有人吗,挖个坟。。。
swiper编译后下面有个div 的class: uni-swiper .uni-swiper-wrapper 设置了position:relative;和height:100%;
导致该div会对照父布局的height,也就是150px;
我是这样解决的:
//自动填充满父布局
swiper {
display:flex;
flex: 1 1 auto;
}
//使用first-child覆盖uni-swiper .uni-swiper-wrapper,将position覆盖为position: absolute;
//或将height:100%干掉也行
swiper :first-child{
position: absolute;
}
酒菜儿
亲测可用
愿随风丶飘雪
感谢,根据您的思路已解决
2020-12-21 18:19