uniapp获得控件宽度(H5、小程序)

H5端获得控件的宽度
// #ifdef H5
let width= this.$el.querySelector('.btn').clientWidth;				
// #endif

微信小程序获得控件的宽度
// #ifdef MP
let width= 0;
				
var query = this.createSelectorQuery();
query.select('.btn').boundingClientRect(
      function(rect){
            if(rect.width){
                  width=rect.width;	
	      }
	}
      ).exec();								
// #endif

参考链接:SelectorQuery wx.createSelectorQuery()

posted @ 2020-09-26 14:42  ,,,沙子,,,  阅读(1530)  评论(0编辑  收藏  举报