nav-bar.nvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="container">
  3. <uni-nav-bar :fixed="true" color="#ffffff" background-color="#007AFF" :status-bar="true" left-icon="arrowleft"
  4. left-text="返回" title="uni-nav-bar 标题" @clickLeft="back" />
  5. <uni-card is-full :isShadow="false">
  6. <text
  7. class="uni-h6">本导航栏为自定义组件,并非原生导航栏。除非原生导航栏无法满足需求,否则不推荐使用自定义导航栏组件。具体参考https://ask.dcloud.net.cn/article/34921</text>
  8. </uni-card>
  9. <uni-section title="基本用法" type="line" style="margin-bottom: 3px;">
  10. <uni-nav-bar left-icon="left" title="标题" @clickLeft="back" />
  11. </uni-section>
  12. <uni-section title="左右显示文字" type="line" style="margin-bottom: 3px;">
  13. <uni-nav-bar left-icon="left" right-text="菜单" left-text="返回" title="标题" @clickLeft="back" />
  14. </uni-section>
  15. <uni-section title="插入slot" type="line" style="margin-bottom: 3px;">
  16. <uni-nav-bar :fixed="false" color="#333333" background-color="#FFFFFF" right-icon="scan" @clickLeft="showCity"
  17. @clickRight="scan">
  18. <block slot="left">
  19. <view class="city">
  20. <view>
  21. <text class="uni-nav-bar-text">{{ city }}</text>
  22. </view>
  23. <uni-icons type="arrowdown" color="#333333" size="22" />
  24. </view>
  25. </block>
  26. <view class="input-view">
  27. <uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
  28. <input confirm-type="search" class="nav-bar-input" type="text" placeholder="输入搜索关键词"
  29. @confirm="confirm" />
  30. </view>
  31. </uni-nav-bar>
  32. </uni-section>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. components: {},
  38. data() {
  39. return {
  40. city: '北京'
  41. }
  42. },
  43. methods: {
  44. back() {
  45. uni.navigateBack({
  46. delta: 1
  47. })
  48. },
  49. showMenu() {
  50. uni.showToast({
  51. title: '菜单'
  52. })
  53. },
  54. clickLeft() {
  55. uni.showToast({
  56. title: '左侧按钮'
  57. })
  58. },
  59. search() {
  60. uni.showToast({
  61. title: '搜索'
  62. })
  63. },
  64. showCity() {
  65. uni.showToast({
  66. title: '选择城市'
  67. })
  68. },
  69. scan() {
  70. uni.showToast({
  71. title: '扫码'
  72. })
  73. },
  74. confirm() {
  75. uni.showToast({
  76. title: '搜索'
  77. })
  78. }
  79. },
  80. onPullDownRefresh() {
  81. console.log('onPullDownRefresh')
  82. setTimeout(function() {
  83. uni.stopPullDownRefresh()
  84. console.log('stopPullDownRefresh')
  85. }, 1000)
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. $nav-height: 30px;
  91. /* #ifndef APP-NVUE */
  92. page {
  93. height: 120%;
  94. }
  95. /* #endif */
  96. .uni-nav-bar-text {
  97. font-size: 12px;
  98. }
  99. .city {
  100. /* #ifndef APP-PLUS-NVUE */
  101. display: flex;
  102. /* #endif */
  103. flex-direction: row;
  104. align-items: center;
  105. justify-content: flex-start;
  106. // width: 160rpx;
  107. margin-left: 4px;
  108. }
  109. .input-view {
  110. /* #ifndef APP-PLUS-NVUE */
  111. display: flex;
  112. /* #endif */
  113. flex-direction: row;
  114. // width: 500rpx;
  115. flex: 1;
  116. background-color: #f8f8f8;
  117. height: $nav-height;
  118. border-radius: 15px;
  119. padding: 0 15px;
  120. flex-wrap: nowrap;
  121. margin: 7px 0;
  122. line-height: $nav-height;
  123. }
  124. .input-uni-icon {
  125. line-height: $nav-height;
  126. }
  127. .nav-bar-input {
  128. height: $nav-height;
  129. line-height: $nav-height;
  130. /* #ifdef APP-PLUS-NVUE */
  131. width: 370rpx;
  132. /* #endif */
  133. padding: 0 5px;
  134. font-size: 14px;
  135. background-color: #f8f8f8;
  136. }
  137. .example-body {
  138. /* #ifndef APP-NVUE */
  139. display: block;
  140. /* #endif */
  141. padding: 0;
  142. }
  143. </style>