<thead id="jxdzp"><address id="jxdzp"><pre id="jxdzp"></pre></address></thead>

<em id="jxdzp"><span id="jxdzp"></span></em>

    <listing id="jxdzp"><nobr id="jxdzp"><meter id="jxdzp"></meter></nobr></listing>

      <address id="jxdzp"></address>
      <noframes id="jxdzp"><form id="jxdzp"><th id="jxdzp"></th></form>
      <noframes id="jxdzp"><form id="jxdzp"><th id="jxdzp"></th></form>

          訂閱本欄目 RSS您所在的位置: 深山工作室 > uni-app > 正文

          uni-app 搜索、歷史記錄功能簡單實現

          2020/12/11 23:19:01 字體: 瀏覽 4455
          實現功能
          1.點擊搜索,把搜索的值存入本地記錄,并展示
          2.搜索相同的值,要刪除舊數據,把新數據放進數組首位
          3.清空歷史記錄


          <template>
          <view>
          <!-- 搜索框 -->
          <view class="search">
          <view style="display: flex;align-items: center;">
          <text class="iconfont icon-sousuo position-absolute text-muted"></text>
          <input class="searchInput" v-model="inputValue" @confirm="search" placeholder="搜索" type="text" />
          </view>
          <view>取消</view>
          </view>
          <!-- 搜索框 -->

          <!-- 搜索歷史 -->
          <view class="searchHistory">
          <view style="display: flex;align-items: center;justify-content: space-between;box-sizing: border-box;padding: 0px 5px;">
          <view>搜索歷史:</view>

          <view style="color: red;font-size: 28px;" @click="empty">×</view>
          </view>
          <view class="searchHistoryItem">
          <view v-for="(item, index) in searchHistoryList" :key="index">
          <text>{{ item }}</text>
          </view>
          </view>
          </view>
          <!-- 搜索歷史 -->
          </view>
          </template>

          <script>
          export default {
          data() {
          return {
          inputValue: '',
          searchHistoryList: [] //搜索出來的內容
          };
          },
          methods: {
          search() {
          if (this.inputValue == '') {
          uni.showModal({
          title: '搜索內容不能為空'
          });
          } else {
          if (!this.searchHistoryList.includes(this.inputValue)) {
          this.searchHistoryList.unshift(this.inputValue);
          uni.setStorage({
          key: 'searchList',
          data: JSON.stringify(this.searchHistoryList)
          });
          } else {
          //有搜索記錄,刪除之前的舊記錄,將新搜索值重新push到數組首位
          let i = this.searchHistoryList.indexOf(this.inputValue);
          this.searchHistoryList.splice(i, 1);
          this.searchHistoryList.unshift(this.inputValue);
          uni.showToast({
          title: '不能重復添加'
          });
          uni.setStorage({
          key: 'searchList',
          data: JSON.stringify(this.searchHistoryList)
          });
          }
          }
          },
          //清空歷史記錄
          empty() {
          uni.showToast({
          title: '已清空'
          });
          uni.removeStorage({
          key: 'searchList'
          });

          this.searchHistoryList = [];
          }
          },
          async onLoad() {
          let list = await uni.getStorage({
          key: 'searchList'
          });

          console.log(list[1].data);

          if (list[1].data) {
          this.searchHistoryList = JSON.parse(list[1].data);
          }
          }
          };
          </script>

          <style>
          .search {
          width: 100%;
          height: 30px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          box-sizing: border-box;
          padding: 0px 15px;
          }
          .searchInput {
          background-color: #f8f9fa;
          width: 220px;
          margin-left: 5px;
          }
          .searchHistory {
          width: 100%;
          margin-top: 5px;
          }
          .searchHistoryItem {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          }
          .searchHistoryItem view {
          /* width: 50px; */
          height: 20px;
          border: 1px solid #eee;
          margin: 0px 5px;
          }
          </style>


          相關閱讀
          鄧州市途鴻旅行社
          一個可以說是超級變態,超級強的DIV+CSS應用
          asp計算頁面執行時間顯示到毫秒
          不凡商旅網
          window.location.href跳轉無反應不跳轉解決
          網站最近更新緩慢說明
          安卓ES文件瀏覽器訪問電腦上共享文件夾設置
          如何徹底卸載電腦里你不想用的軟件
          共有0條關于《uni-app 搜索、歷史記錄功能簡單實現》的評論
          發表評論
          正在加載評論......
          返回頂部發表評論
          呢 稱:
          表 情:
          內 容:
          評論內容:不能超過 1000 字,需審核,請自覺遵守互聯網相關政策法規。
          驗證碼: 驗證碼 
          網友評論聲明,請自覺遵守互聯網相關政策法規。

          您發布的評論即表示同意遵守以下條款:
          一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
          二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
          三、本站對您所發布內容擁有處置權。

          更多信息>>欄目類別選擇
          百度小程序開發
          微信小程序開發
          微信公眾號開發
          uni-app
          asp函數庫
          ASP
          DIV+CSS
          HTML
          python
          更多>>同類信息
          uni-app開發表單input組件的一些規則說明自己預留使用
          uni-app:使用uni.downloadFile下載word或pdf文件并保存到手機
          小程序中利用addPhoneContact將聯系人的信息添加到手機通訊錄支持保存聯系人頭像
          微信小程序打開客服提示:該小程序提供的服務出現故障,請稍后重試
          微信小程序客服會話只能過button讓用戶主動觸發
          uni-app開發微信小程序使用button的open-type為contact調用微信客服不能用view或者js調用
          更多>>最新添加文章
          dw里面查找替換使用正則刪除sqlserver里面的CONSTRAINT
          Android移動端自動化測試:使用UIAutomatorViewer與Selenium定位元素
          抖音直播音掛載小雪花 懂車帝小程序
          javascript獲取瀏覽器指紋可以用來做投票
          火狐Mozilla Firefox出現:無法載入您的Firefox配置文件 它可能已經丟失 或是無法訪問 問題解決集合處理辦法
          在Android、iOS、Windows、MacOS中微信小程序的文件存放路徑
          python通過代碼修改pip下載源讓下載庫飛起
          python里面requests.post返回的res.text還有其它的嗎
          更多>>隨機抽取信息
          asp中eof的介紹
          asp判斷是否是手機訪問
          ASP過濾SQL中的非法字符并格式化相關的html代碼
          uni-app跨端開發微信小程序時頁面棧超過10層時小程序像卡死一樣假性不能點擊無法跳轉的解決方案
          web2.0網頁--常用的XHTML標簽的使用技巧方法介紹
          asp論壇制作教程(二)——asp論壇制作文件關系發析
          88国产精品视频一区二区三区