nav-bar.nvue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view>
  3. <uni-nav-bar color="#ffffff" background-color="#007AFF" :status-bar="true" left-icon="arrowleft" left-text="返回" title="标题" @clickLeft="back" />
  4. <text class="example-info">本导航栏为自定义组件,并非原生导航栏。除非原生导航栏无法满足需求,否则不推荐使用自定义导航栏组件。具体参考https://ask.dcloud.net.cn/article/34921</text>
  5. <uni-section title="基本用法" type="line"></uni-section>
  6. <view class="example-body">
  7. <uni-nav-bar left-icon="arrowleft" title="标题" @clickLeft="back" />
  8. </view>
  9. <uni-section title="左右显示文字" type="line"></uni-section>
  10. <view class="example-body">
  11. <uni-nav-bar left-icon="arrowleft" right-text="菜单" left-text="返回" title="标题" @clickLeft="back" />
  12. </view>
  13. <uni-section title="插入slot" type="line"></uni-section>
  14. <view class="example-body">
  15. <uni-nav-bar :fixed="false" color="#333333" background-color="#FFFFFF" right-icon="scan" @clickLeft="showCity" @clickRight="scan">
  16. <block slot="left">
  17. <view class="city">
  18. <view><text class="uni-nav-bar-text">{{ city }}</text></view>
  19. <uni-icons type="arrowdown" color="#333333" size="22" />
  20. </view>
  21. </block>
  22. <view class="input-view">
  23. <uni-icons class="input-uni-icon" type="search" size="22" color="#666666" />
  24. <input confirm-type="search" class="nav-bar-input" type="text" placeholder="输入搜索关键词" @confirm="confirm">
  25. </view>
  26. </uni-nav-bar>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. components: {},
  33. data() {
  34. return {
  35. city: '北京'
  36. }
  37. },
  38. methods: {
  39. back() {
  40. uni.navigateBack({
  41. delta: 1
  42. })
  43. },
  44. showMenu() {
  45. uni.showToast({
  46. title: '菜单'
  47. })
  48. },
  49. clickLeft() {
  50. uni.showToast({
  51. title: '左侧按钮'
  52. })
  53. },
  54. search() {
  55. uni.showToast({
  56. title: '搜索'
  57. })
  58. },
  59. showCity() {
  60. uni.showToast({
  61. title: '选择城市'
  62. })
  63. },
  64. scan() {
  65. uni.showToast({
  66. title: '扫码'
  67. })
  68. },
  69. confirm() {
  70. uni.showToast({
  71. title: '搜索'
  72. })
  73. }
  74. },
  75. onPullDownRefresh() {
  76. console.log('onPullDownRefresh')
  77. setTimeout(function() {
  78. uni.stopPullDownRefresh()
  79. console.log('stopPullDownRefresh')
  80. }, 1000)
  81. }
  82. }
  83. </script>
  84. <style>
  85. @charset "UTF-8";
  86. /* 头条小程序组件内不能引入字体 */
  87. /* #ifdef MP-TOUTIAO */
  88. @font-face {
  89. font-family: uniicons;
  90. font-weight: normal;
  91. font-style: normal;
  92. src: url("~@/static/uni.ttf") format("truetype");
  93. }
  94. /* #endif */
  95. /* #ifndef APP-NVUE */
  96. page {
  97. display: flex;
  98. flex-direction: column;
  99. box-sizing: border-box;
  100. background-color: #efeff4;
  101. min-height: 100%;
  102. height: auto;
  103. }
  104. view {
  105. font-size: 14px;
  106. line-height: inherit;
  107. }
  108. .example {
  109. padding: 0 15px 15px;
  110. }
  111. .example-info {
  112. padding: 15px;
  113. color: #3b4144;
  114. background: #ffffff;
  115. }
  116. .example-body {
  117. /* #ifndef APP-NVUE */
  118. display: flex;
  119. /* #endif */
  120. flex-direction: row;
  121. flex-wrap: wrap;
  122. justify-content: center;
  123. padding: 0;
  124. font-size: 14px;
  125. background-color: #ffffff;
  126. }
  127. /* #endif */
  128. .example {
  129. padding: 0 15px;
  130. }
  131. .example-info {
  132. /* #ifndef APP-NVUE */
  133. display: block;
  134. /* #endif */
  135. padding: 15px;
  136. color: #3b4144;
  137. background-color: #ffffff;
  138. font-size: 14px;
  139. line-height: 20px;
  140. }
  141. .example-info-text {
  142. font-size: 14px;
  143. line-height: 20px;
  144. color: #3b4144;
  145. }
  146. .example-body {
  147. flex-direction: column;
  148. padding: 15px;
  149. background-color: #ffffff;
  150. }
  151. .word-btn-white {
  152. font-size: 18px;
  153. color: #FFFFFF;
  154. }
  155. .word-btn {
  156. /* #ifndef APP-NVUE */
  157. display: flex;
  158. /* #endif */
  159. flex-direction: row;
  160. align-items: center;
  161. justify-content: center;
  162. border-radius: 6px;
  163. height: 48px;
  164. margin: 15px;
  165. background-color: #007AFF;
  166. }
  167. .word-btn--hover {
  168. background-color: #4ca2ff;
  169. }
  170. .uni-nav-bar-text {
  171. font-size: 14px;
  172. }
  173. .city {
  174. /* #ifndef APP-PLUS-NVUE */
  175. display: flex;
  176. /* #endif */
  177. flex-direction: row;
  178. align-items: center;
  179. justify-content: flex-start;
  180. margin-left: 4px;
  181. }
  182. .input-view {
  183. /* #ifndef APP-PLUS-NVUE */
  184. display: flex;
  185. /* #endif */
  186. flex-direction: row;
  187. flex: 1;
  188. background-color: #f8f8f8;
  189. height: 30px;
  190. border-radius: 15px;
  191. padding: 0 15px;
  192. flex-wrap: nowrap;
  193. margin: 7px 0;
  194. line-height: 30px;
  195. }
  196. .input-uni-icon {
  197. line-height: 30px;
  198. }
  199. .nav-bar-input {
  200. height: 30px;
  201. line-height: 30px;
  202. /* #ifdef APP-PLUS-NVUE */
  203. width: 370rpx;
  204. /* #endif */
  205. padding: 0 5px;
  206. font-size: 14px;
  207. background-color: #f8f8f8;
  208. }
  209. .example-body {
  210. /* #ifndef APP-NVUE */
  211. display: block;
  212. /* #endif */
  213. padding: 0;
  214. }
  215. </style>