export default {
data() {
return {
height_home: 0,
swiperHeight: 0,
}
}
//獲取高度時有時會獲取失敗,所以這里要預先執行
onReady() {
this.getSysHeight();
},
methods: {
//獲取屏幕信息
getSystemInfo() {
let that = this;
uni.getSystemInfo({
success: res => {
// console.log("獲取手機參數信息");
// console.log(res);
that.height_home = res.windowHeight;
// const query = uni.createSelectorQuery() // query 是 SelectorQuery 對象
// query.select('.footer').boundingClientRect() // select 后是 NodesRef 對象,然后 boundingClientRect 返回 SelectorQuery 對象
// query.exec(function(res) { // exec 返回 NodesRef 對象
// // console.log(res[0].top);
// console.log("獲取元素");
// console.log(res);
// that.swiperHeight = res[0].height;
// // #the-id節點的上邊界坐標
// // res[1].scrollTop // 顯示區域的豎直滾動位置
// // that.swiperHeight = top
uni.setStorageSync('SystemInfo',res);
that.getSysHeight();
// })
}
})
},
getSysHeight() {
let that = this;
let info = uni.createSelectorQuery().select('.footer');
info.boundingClientRect(data => {
// console.log("獲取元素寬度");
// console.log(data);
if (data) {
if (data.height && data.height == '' || data.height && data.height == null || data.height && data.height ==
'null') {
that.getSysHeight();
}
that.swiperHeight = data.height;
}
// console.log("swiper的高度" + that.swiperHeight);
}).exec();
},
<view class="home" :style="{ height: height_home +'px' }"> <view class="footer"> <swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" class="swiper-item2" :style="{height:swiperHeight+'px'}"> <swiper-item v-for="(ite,inde) in tabs"> <scroll-view scroll-y :style="{height:swiperHeight+'px'}"></scroll-view> </swiper-item> </swiper> </view> </view>