获取屏幕高度:
onShow() {
uni.getSystemInfo({
success: res => {
this.windowHeight = res.windowHeight;
console.log(res.windowHeight) //res.windowHeight是返回的屏幕高度
}
});
},
获取元素高度:
onLoad() {
this.$nextTick(() => {
this.setSwiperHeight();
});
},
setSwiperHeight() {
let query = uni.createSelectorQuery().in(this);
query.select('#imgBox').boundingClientRect(); //我找的idimgBox 你的替换就行
query.exec(res => {
console.log(res[0].height) // 元素高度
this.swiperHeight = res[0].height; // 返回的值可以用作动态修改swiper高度
});
},
修改元素高度或者动态修改 uniapp自带的swiper组件的高度
可以这样: swiperHeight 是上图获取元素高度的值
<swiper class="" :style="{ height: swiperHeight + 'px' }" :current="current" @change="changeSwiper">
</swiper>