123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <template>
- <view class="navbar">
- <!-- 状态栏高度 -->
- <view class="status-bar" :style="{'height': geStatusBarHeight() + 'px'}"></view>
- <!-- 导航栏高度 -->
- <view class="bar-content" :style="{'height': getNavBarHeight()+'px'}">
- <slot></slot>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'Navbar',
- props: {
- title: {
- type: String,
- default: ''
- }
- },
- methods: {
- geStatusBarHeight() {
- return uni.getSystemInfoSync()['statusBarHeight']
- },
- getNavBarHeight() {
- // #ifdef MP-WEIXIN
- let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
- // 导航栏高度 = 胶囊高度 + 上间距 + 下间距 + 微调 (menuButtonInfo.top - uni.getSystemInfoSync()['statusBarHeight'] = 上间距)
- let navbarHeight = menuButtonInfo.height + (menuButtonInfo.top - uni.getSystemInfoSync()[
- 'statusBarHeight']) * 2 + 4
- // #endif
- // #ifdef APP-PLUS || H5
- let navbarHeight = 44
- // #endif
- return navbarHeight
- },
- navigateBack() {
- uni.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .navbar {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- z-index: 1996;
- .status-bar {
- background: #fff;
- }
- .bar-content {
- position: relative;
- }
- }
- </style>
|