uni-app 高度自适应

方法一已知固定高度
**注意 scrollH 初始值不等大于最终显示的高度,如果封装组件,onReady () **

    onLoad() {
        // 获取可视区域高度,减去固定高度
        uni.getSystemInfo({
            success: res => {
                this.scrollH = res.windowHeight - uni.upx2px(82);
            }
        });
    },


方法二 动态获取固定高度

    onLoad() {
        this.$nextTick(function() {
            uni.getSystemInfo({
                success: res => {
                    const query = uni.createSelectorQuery().in(this);
                    query.select('#scrollH').boundingClientRect(data => {
                            // this.scrollH = `${data.height}px;`;
                            console.log(data.height)
                        }).exec();
                }
            });
        });
    },


方法三 使用flex,封装组件

猜你喜欢

转载自blog.csdn.net/m0_46461853/article/details/126896789
今日推荐