美文网首页
设置view到底部的高度

设置view到底部的高度

作者: 杨义林 | 来源:发表于2020-09-07 14:29 被阅读0次

1.得到view到上部的距离

const query = wx.createSelectorQuery()
            query.select('#src_box').boundingClientRect()
            query.selectViewport().scrollOffset()
            query.exec((res) =>{
                console.log(res);
                this.boxToTop = res[0].top
            })

2.得到屏幕的高度

uni.getSystemInfo({
                success: res => {
                    this.windowH = res.windowHeight
                }
            })

3.添加计算属性,得到的值传给子组件

computed: {
            getHeight() {
                this.boxHeight = this.windowH - this.boxToTop
            }
        }

4.子组件接收后,给view添加样式
<view class="content" :style="{height: boxHeight + 'px'}">

相关文章

网友评论

      本文标题:设置view到底部的高度

      本文链接:https://www.haomeiwen.com/subject/nuzkektx.html