0
点赞
收藏
分享

微信扫一扫

uni-app 获取元素尺寸

Raow1 2022-11-09 阅读 206

比如有个view元素如下

<view style="height:100px;width:100%;background:black;" res="topbox"></view>

可以这样获取

getRefs(){
let that = this
return new Promise((resolve,reject)=>{
resolve(that.$refs)
})
}

that.getRefs().then(res=>{
that.top_height = res.topbox.$el.offsetHeight
})

以上是uniapp中封装过的元素,比如view

如果是传统html元素,获取如下

this.$refs.topbox.offsetHeight


举报

相关推荐

0 条评论