uni-navbar-lite.vue 1.8 KB
Newer Older
M
mehaotian 已提交
1
<template>
2 3 4 5 6 7 8 9 10 11 12
  <view class="uni-navbar">
    <view class="uni-navbar-inner" :style="navbarStyle">
      <view class="left-content" @click="back">
        <text class="uni-icons uniui-back"></text>
      </view>
      <view class="uni-navbar-content">
        <slot>{{title}}</slot>
      </view>
      <view class="right-content">
        <slot name="right"></slot>
      </view>
M
mehaotian 已提交
13
    </view>
14
  </view>
M
mehaotian 已提交
15 16 17
</template>

<script>
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  export default {
    name: "uni-navbar",
    props: {
      title: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        statusBarHeight: 0
      };
    },
    computed: {
      navbarStyle() {
        return `margin-top:${this.statusBarHeight}px`
      },
    },
    created() {
      const sys = uni.getSystemInfoSync()
      const statusBarHeight = sys.statusBarHeight
      this.statusBarHeight = statusBarHeight
    },
    methods: {
      back() {
        uni.navigateBack({})
      }
    },
  }
M
mehaotian 已提交
47 48 49
</script>

<style>
50
  @import './uni-icons.css';
M
mehaotian 已提交
51

52 53 54 55 56 57 58 59
  .uni-icons {
    font-family: UniIconsLight;
    text-decoration: none;
    text-align: center;
    font-size: 22px;
    font-style: normal;
    color: #333;
  }
M
mehaotian 已提交
60

61 62 63 64
  .uni-navbar {
    border: 1px #eee solid;
    background-color: #fff;
  }
M
mehaotian 已提交
65

66 67 68 69 70 71
  .uni-navbar-inner {
    position: relative;
    flex-direction: row;
    justify-content: space-between;
    height: 45px;
  }
M
mehaotian 已提交
72

73 74 75 76 77 78 79
  .left-content,
  .right-content {
    justify-content: center;
    align-items: center;
    width: 45px;
    height: 100%;
  }
M
mehaotian 已提交
80

81 82 83 84 85 86 87 88 89 90
  .uni-navbar-content {
    position: absolute;
    height: 100%;
    top: 0;
    bottom: 0;
    left: 45px;
    right: 45px;
    justify-content: center;
    align-items: center;
  }
M
mehaotian 已提交
91
</style>