tnblog
首页
视频
资源
登录
什么时候才能领悟,取之越多失之越多
排名
5
文章
229
粉丝
15
评论
7
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

uni-app标题导航栏官方例子

3932人阅读 2022/2/15 13:55 总访问:1165847 评论:0 收藏:0 手机
分类: 移动开发

例子位置:

源码:

  1. <template>
  2. <view class="page">
  3. <swiper indicator-dots="true">
  4. <swiper-item v-for="(img, key) in imgUrls" :key="key"><image :src="img" /></swiper-item>
  5. </swiper>
  6. <view class="uni-padding-wrap uni-common-mt">
  7. <view class="uni-title">
  8. <view>本示例为导航栏带搜索框完整功能演示,主要演示有:</view>
  9. <view>1. 导航栏为 transparent 模式,向上滑动页面,导航栏会从透明变为实色。</view>
  10. <view>2. 点击搜索框跳转到搜索页面。</view>
  11. <view>3. 点击导航栏右侧按钮实现关联操作。</view>
  12. <view>4. 搜索页面为提示词搜索,输入内容实时显示关联词。</view>
  13. <view>5. 搜索结果根据搜索内容高亮显示文字。</view>
  14. <view>6. 点击搜索列表或者软键盘搜索按钮,会将结果保存到搜索历史列表。</view>
  15. <view>7. 点击删除图标,清空历史搜索列表。</view>
  16. <view>Tips </view>
  17. <view>1. 本示例目前仅支持 App 端</view>
  18. <view>2. 所有示例均为演示使用,具体逻辑需要自己实现。</view>
  19. </view>
  20. </view>
  21. <view style="height: 1000rpx;"></view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. showSwiper: false,
  29. imgUrls: [
  30. 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/b4b60b10-5168-11eb-bd01-97bc1429a9ff.jpg',
  31. 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/b1dcfa70-5168-11eb-bd01-97bc1429a9ff.jpg'
  32. ]
  33. };
  34. },
  35. /**
  36. * 当 searchInput 配置 disabled 为 true 时触发
  37. */
  38. onNavigationBarSearchInputClicked(e) {
  39. console.log('事件执行了')
  40. uni.navigateTo({
  41. url: '/pages/template/nav-search-input/detail/detail'
  42. });
  43. },
  44. /**
  45. * 点击导航栏 buttons 时触发
  46. */
  47. onNavigationBarButtonTap() {
  48. uni.showModal({
  49. title: '提示',
  50. content: '用户点击了功能按钮,这里仅做展示。',
  51. success: res => {
  52. if (res.confirm) {
  53. console.log('用户点击了确定');
  54. }
  55. }
  56. });
  57. }
  58. };
  59. </script>
  60. <style>
  61. image,
  62. swiper,
  63. .img-view {
  64. width: 750rpx;
  65. width: 100%;
  66. height: 500rpx;
  67. }
  68. .page-section-title {
  69. margin-top: 50rpx;
  70. }
  71. </style>

详情页:

  1. <template>
  2. <view class="wrapper">
  3. <view v-if="isHistory" class="history-box">
  4. <view v-if="historyList.length > 0">
  5. <view class="history-title">
  6. <text>搜索历史</text>
  7. <text class="uni-icon uni-icon-trash" @click="clearSearch"></text>
  8. </view>
  9. <view class="history-content">
  10. <view class="history-item" v-for="(item, index) in historyList" :key="index">
  11. {{ item.name }}
  12. </view>
  13. </view>
  14. </view>
  15. <view v-else class="no-data">您还没有历史记录</view>
  16. </view>
  17. <view v-else class="history-box">
  18. <view v-if="historyList.length > 0" class="history-list-box">
  19. <view
  20. class="history-list-item"
  21. v-for="(item, index) in historyList"
  22. :key="index"
  23. @click="listTap(item)"
  24. >
  25. <rich-text :nodes="item.nameNodes"></rich-text>
  26. </view>
  27. </view>
  28. <view v-else class="no-data">没有搜索到相关内容</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import util from '@/components/amap-wx/js/util.js';
  34. export default {
  35. data() {
  36. return {
  37. historyList: [],
  38. isHistory: true,
  39. list: [],
  40. flng: true,
  41. timer: null
  42. };
  43. },
  44. onLoad() {
  45. // 本示例用的是高德 sdk ,请根据具体需求换成自己的服务器接口。
  46. this.amapPlugin = util.mapInit();
  47. this.historyList = uni.getStorageSync('search:history');
  48. },
  49. methods: {
  50. /**
  51. * 列表点击
  52. */
  53. listTap(item) {
  54. item = JSON.parse(JSON.stringify(item));
  55. // 如果当前是历史搜索页面 ,那么点击不储存,直接 跳转
  56. if (this.history) {
  57. return;
  58. } else {
  59. this.isHistory = true;
  60. // 去做一些相关搜索功能 ,这里直接返回到上一个页面
  61. // 点击列表存储搜索数据
  62. util.setHistory(item);
  63. uni.navigateBack();
  64. }
  65. },
  66. /**
  67. * 清理历史搜索数据
  68. */
  69. clearSearch() {
  70. uni.showModal({
  71. title: '提示',
  72. content: '是否清理全部搜索历史?该操作不可逆。',
  73. success: res => {
  74. if (res.confirm) {
  75. this.historyList = util.removeHistory();
  76. }
  77. }
  78. });
  79. },
  80. /**
  81. * 关键字搜索
  82. * 调用高德地图关键字搜索api
  83. */
  84. getInputtips(val) {
  85. let _this = this;
  86. this.amapPlugin.getInputtips({
  87. keywords: val,
  88. city: '北京',
  89. success: data => {
  90. let dataObj = data.tips;
  91. // 处理返回数据文字高亮
  92. dataObj.map(item => {
  93. return util.dataHandle(item, val);
  94. });
  95. //成功回调
  96. _this.historyList = dataObj;
  97. },
  98. fail: info => {
  99. //失败回调
  100. console.log(info);
  101. }
  102. });
  103. }
  104. },
  105. /**
  106. * 当 searchInput 输入时触发
  107. */
  108. onNavigationBarSearchInputChanged(e) {
  109. let text = e.text;
  110. if (!text) {
  111. this.isHistory = true;
  112. this.historyList = [];
  113. this.historyList = uni.getStorageSync('search:history');
  114. return;
  115. } else {
  116. this.isHistory = false;
  117. this.getInputtips(text);
  118. }
  119. },
  120. /**
  121. * 点击软键盘搜索按键触发
  122. */
  123. onNavigationBarSearchInputConfirmed(e) {
  124. let text = e.text;
  125. if (!text) {
  126. this.isHistory = true;
  127. this.historyList = [];
  128. this.historyList = uni.getStorageSync('search:history');
  129. uni.showModal({
  130. title: '提示',
  131. content: '请输入内容。',
  132. success: res => {
  133. if (res.confirm) {
  134. }
  135. }
  136. });
  137. return;
  138. } else {
  139. uni.showModal({
  140. title: '提示',
  141. content: `您输入的内容为"${text}",如果点击确定,将记录到历史搜索,并返回.如果取消不做操作`,
  142. success: res => {
  143. if (res.confirm) {
  144. util.setHistory(text);
  145. uni.navigateBack();
  146. }
  147. }
  148. });
  149. }
  150. },
  151. /**
  152. * 点击导航栏 buttons 时触发
  153. */
  154. onNavigationBarButtonTap() {
  155. uni.showModal({
  156. title: '提示',
  157. content: '点击确定,修改输入框的内容为abc',
  158. success: res => {
  159. if (res.confirm) {
  160. const currentWebview = this.$mp.page.$getAppWebview();
  161. currentWebview.setTitleNViewSearchInputText("abc");
  162. }
  163. }
  164. });
  165. }
  166. };
  167. </script>
  168. <style>
  169. .history-title {
  170. display: flex;
  171. justify-content: space-between;
  172. padding: 20rpx 30rpx;
  173. padding-bottom: 0;
  174. font-size: 34rpx;
  175. color: #333;
  176. }
  177. .history-title .uni-icon {
  178. font-size: 40rpx;
  179. }
  180. .history-content {
  181. display: flex;
  182. flex-wrap: wrap;
  183. padding: 15rpx;
  184. }
  185. .history-item {
  186. padding: 4rpx 35rpx;
  187. border: 1px #f1f1f1 solid;
  188. background: #fff;
  189. border-radius: 50rpx;
  190. margin: 12rpx 10rpx;
  191. color: #999;
  192. }
  193. .history-list-box {
  194. /* margin: 10rpx 0; */
  195. }
  196. .history-list-item {
  197. padding: 30rpx 0;
  198. margin-left: 30rpx;
  199. border-bottom: 1px #EEEEEE solid;
  200. font-size: 28rpx;
  201. }
  202. .no-data {
  203. text-align: center;
  204. color: #999;
  205. margin: 100rpx;
  206. }
  207. </style>

页面配置:

  1. {
  2. "path": "nav-search-input/nav-search-input",
  3. "style": {
  4. "navigationBarTitleText": "导航栏带搜索框",
  5. "app-plus": {
  6. "titleNView": {
  7. "type": "transparent",
  8. "titleColor": "#fff",
  9. "backgroundColor": "#007AFF",
  10. "buttons": [{
  11. "fontSrc": "/static/uni.ttf",
  12. "text": "\ue537",
  13. "width": "40px",
  14. "fontSize": "28px",
  15. "color": "#fff",
  16. "background": "rgba(0,0,0,0)"
  17. }],
  18. "searchInput": {
  19. "backgroundColor": "#fff",
  20. "borderRadius": "6px",
  21. "placeholder": "请输入地址 如:大钟寺",
  22. "disabled": true
  23. }
  24. }
  25. }
  26. }
  27. }

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

uni-app开始时间与结束时间(结束时间大于开始时间)picker编写

利用uni-app官网里面picker插件代码当点击开始时间后结束时间要大于选择后的开始时间,点击结束时间后开始时间要小于开始时...

uni-app用法与html标签的变化

以前是html标签,比如,现在是小程序组件,比如。那么标签和组件有什么区别,不都是用尖括号包围起来一段英文吗?其实标签...

uni-app无法导入插件

点击网页中右上角的插件导入,可以打开项目,但是就是无法导入插件。是因为,要登录!hbuilder里边也要登录才行,他这个应...

使用uni-app的云端一体插件

初次使用uni-app的云端一体插件步骤还是有点多,也有一些坑,在这里把使用过程记录一下。 一:先下载需要的插件在插件右上...

uni-app中list插件图标问题

如图:他使用uni-icons实现的如果只有text就不会有图标有时候贴的文档不是太完善,还是要下一个完整的插件来对比一下

uni-app发起请求

代码如下:uni.request({ url:&#39;接口地址&#39;, success:(result)=&gt;{ my.lists=result.data; } })注意你的...

uni-app官方文档

https://uniapp.dcloud.io/

uni-app运行与调试

上边有菜单,可以运行到浏览器,也可以运行到内置浏览器运行到内置浏览器的效果:

uni-app引入外部资源,引入外网样式

很简单代码如下:&lt;style&gt; @import&#39;http://image.tnblog.net/amazeui.min.css&#39;; &lt;/style&gt; &lt;st...

uni-app设置起始页

很简单,在pages.json里边配置即可。

uni-app页面无法跳转问题

首先检查一下有没有在pages里边配置没有配置不行的哦或者看看你的跳转方式对不对,如果跳转的是底部菜单,但是你用的是uni....

uni-app 删除失败 setting denied access to....

删除的时候如果文件夹下面还有页面,这样直接删除文件夹是会报错的:删除失败 setting denied access to....这种情况就直接...

uni-app中引入外部js

可以使用代码如下:varscript=document.createElement(&#39;script&#39;); script.src=&quot;http://image.tnblog.net/jqu...

uni-app dom操作

比如引入外部js需要用到的dom操作:varscript=document.createElement(&#39;script&#39;); script.src=&quot;http://image....

uni-app使用web-view引入页面

代码如下:&lt;template&gt; &lt;viewclass=&quot;h5-html&quot;&gt; &lt;web-view:webview-styles=&quot;webviewStyl...

uni-app真机调试

很简单只要手机开启了usb调试,然后hbuilderx会自动获取到手机的然后运行到手机即可华为手机开启use调试:一直点击版本号进...
亲近你的朋友,但更要亲近你的敌人。