uni-app跨端获取组件尺寸

uni-app的语法和js很像,但在app端,不能使用浏览器自带对象,如document、window、localstorage、cookie等,更不能使用jquery等依赖这些浏览器对象的框架。因为各家小程序快应用都不支持这些对象。像下面的方法获取控件的高度,在app端都是不支持的。

this.$refs.component.$el.offsetHeight
<view ref="wrap" id="wrap">
mounted() {
	// 计算定位元素高度,给浮动元素下的空元素高度
	let view = uni.createSelectorQuery().in(this).select("#wrap")
	view.fields({
		size: true
	}, res => {
		this.height = res.height - 55 + 'px'
		this.afterHeight = true;
	}).exec()

},
let view = uni.createSelectorQuery().in(this).select(".test"); 
view.fields({ size: true, rect: true }, data => {
    console.log("得到节点信息" + JSON.stringify(data)); 
    //{“left”:0,“right”:320,“top”:348.1000061035156,“bottom”:382.1000061035156,“width”:320,“height”:34}
}).exec();

你可能感兴趣的:(前端,uni-app,javascript,前端)