美文网首页
uniapp工作时用到的知识点

uniapp工作时用到的知识点

作者: 妮儿_smile | 来源:发表于2020-11-03 14:25 被阅读0次

获取某个页面元素的rect属性

uni.createSelectorQuery().select('.card');
boundingClientRect

<view class="card"></view>

// 获取卡片高度
getBtnStyle() {
    let _this = this
    let obj = uni.createSelectorQuery().select('.card')
    //obj包括component,selector,selectorQuery等属性
    obj.boundingClientRect(function(data) { 
    // data包括dataset,top,right,bottom,left,width,height等属性
        _this.btnStyle = "line-height:" + data.height + "rpx";
        _this.$forceUpdate()
    }).exec()
},

注意:

  1. 这个方法要在页面渲染完成之后才可以调用
  2. 如果想要获取屏幕的其他信息,可以使用uni.getSystemInfo;

相关文章

网友评论

      本文标题:uniapp工作时用到的知识点

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