用于做底部悬浮定位,悬浮在tabbar上
在设置tabbar的组件中获取,利用组件生命周期,获取tabbar高度,将高度存到本地,用于全局获取
attached() {
let query = wx.createSelectorQuery().in(this);
query.select('.custom-tab-bar').boundingClientRect(rect => {
console.log('获取tabBar元素的高度', rect);
wx.setStorageSync('tabBarHeight', rect.height) // 将获取到的高度设置缓存,以便之后使用
}).exec();
},
页面中使用,将元素固定到tabbar上方
<view :style="{
width: '100%',
position: 'fixed',
bottom: tabbarHeight + 'px',
}"></view>
export default {
data() {
return {
tabbarHeight: 0,
}
},
onLoad() {
this.tabbarHeight = uni.getStorageSync('tabBarHeight') || 0;
}
}
这样页面就可以动态获取tabbar的高度
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。