uni-navbar-lite.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="uni-navbar">
  3. <view class="uni-navbar-inner" :style="navbarStyle">
  4. <view class="left-content" @click="back">
  5. <text class="uni-icons uniui-back"></text>
  6. </view>
  7. <view class="uni-navbar-content">
  8. <slot>{{title}}</slot>
  9. </view>
  10. <view class="right-content">
  11. <slot name="right"></slot>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: "uni-navbar",
  19. props: {
  20. title: {
  21. type: String,
  22. default: '',
  23. },
  24. showLeft:{
  25. type: Boolean,
  26. default: true
  27. }
  28. },
  29. data() {
  30. return {
  31. statusBarHeight: 0
  32. };
  33. },
  34. computed: {
  35. navbarStyle() {
  36. return `margin-top:${this.statusBarHeight}px`
  37. },
  38. },
  39. created() {
  40. const sys = uni.getSystemInfoSync()
  41. const statusBarHeight = sys.statusBarHeight
  42. this.statusBarHeight = statusBarHeight
  43. },
  44. methods: {
  45. back() {
  46. uni.navigateBack({})
  47. }
  48. },
  49. }
  50. </script>
  51. <style>
  52. @import './uni-icons.css';
  53. .uni-icons {
  54. font-family: UniIconsLight;
  55. text-decoration: none;
  56. text-align: center;
  57. font-size: 22px;
  58. font-style: normal;
  59. color: #333;
  60. }
  61. .uni-navbar {
  62. border: 1px #eee solid;
  63. background-color: #fff;
  64. }
  65. .uni-navbar-inner {
  66. position: relative;
  67. display: flex;
  68. flex-direction: row;
  69. justify-content: space-between;
  70. height: 45px;
  71. }
  72. .left-content,
  73. .right-content {
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. width: 45px;
  78. height: 100%;
  79. }
  80. .uni-navbar-content {
  81. position: absolute;
  82. height: 100%;
  83. top: 0;
  84. bottom: 0;
  85. left: 45px;
  86. right: 45px;
  87. display: flex;
  88. justify-content: center;
  89. align-items: center;
  90. }
  91. </style>