当前位置: 首页 > news >正文

【uniapp 样式】使用setStorageSync存储历史搜索记录

在这里插入图片描述

<template><view><view class="zhuangbox u-flex"><u--inputplaceholder="请输入关键字搜索"border="surround"shape='circle'prefixIcon="search"prefixIconStyle="font-size: 22px;color: #909399"v-model="inputVal"@confirm='searchFun'></u--input><text class="u-m-l-30 u-color-8D4 u-f-s-26" @click="cancelFun">取消</text></view>	<view class="search-keyword"><scroll-view class="keyword-box" scroll-y><view class="keyword-block"><view class="u-flex u-row-between u-p-t-30 u-p-b-30 u-tips-color"><view class="title">历史搜索</view><view @tap="oldDelete"><image src="@/static/img/shanchu.png" mode="" class="u-w-40 u-h-40"></image></view></view><view class="u-flex u-flex-wrap"><view class="u-m-r-15 u-m-b-15" v-for="(keyword, index) in list" @tap="doSearch(keyword)" :key="index"><view class="neirong">{{keyword}}</view></view></view></view></scroll-view></view></view>
</template><script>export default {data() {return {inputVal:'',list:[],}},onShow() {this.inputVal = '';this.getSearchStorage();},methods: {searchFun(){if(!this.inputVal.trim()){this.$u.toast('请输入关键词')return;}this.setSearchStorage(this.inputVal);this.gopage('/pagesA/index/list?keyword='+ this.inputVal);},// 取消cancelFun(){this.inputVal = '';},doSearch(value) {if(!value.trim()){this.$u.toast('请输入关键词')return;}this.active = true;this.inputVal = value;this.gopage('/pagesA/index/list?keyword='+value)},		// 删除历史搜索数据oldDelete(){uni.setStorageSync('search_key','');this.list = [];},// 本地缓存 搜索历史setSearchStorage(searchkey) {// 存一个数组类型// 先取出本地缓存的数据let searchArr=uni.getStorageSync('search_key')||[]// 从前面插入searchArr.unshift(searchkey)uni.setStorageSync('search_key',searchArr)},// 取出本地缓存数据并显示,不会自动执行,放到生命周期函数中getSearchStorage() {let getData = uni.getStorageSync('search_key')// 数组去重let setData = [...new Set(getData)]this.list = setData;},gopage(url) {uni.navigateTo({url:url})},}}
</script>
<style lang="scss">.zhuangbox{background: #FFFFFF;padding: 0 32rpx;.u-input{padding-left: 30rpx !important;background-color:$uni-bg-color-grey;}.u-input.u-border{border-color: transparent !important;}}
</style>
<style lang="scss" scoped>
.search-keyword{padding:0 30rpx 30rpx;.keyword-block{padding-bottom: 30rpx;}
}
.zanwu{margin: 0 auto;
}
.title{font-size: 28rpx;font-weight: 500;color: #181818;
}
.neirong{background: #F5F5F5;border-radius: 28rpx;padding: 10rpx 34rpx;font-size: 26rpx;color: #181818;
}
.u-flex{display: flex;align-items: center;
}
.wrap,.u-flex-wrap{flex-wrap: wrap;
}
.flex_jus_between,.u-row-between{justify-content:space-between;
}
.u-m-l-30{margin-left:30rpx;
}
.u-m-r-15{margin-right:15rpx;
}
.u-m-b-15{margin-bottom:15rpx;
}
.u-p-t-30{padding-top:30rpx;
}
.u-p-b-30{padding-bottom:30rpx;
}
.u-w-40{width:40rpx;
}
. u-h-40 {height:40rpx;
}</style>
http://www.lryc.cn/news/107415.html

相关文章:

  • git remote add origin详解
  • 附录1-将uni-app运行到微信开发者工具
  • 【LeetCode】根据二叉树创建字符串
  • 【图论】强连通分量
  • 网络:VRP介绍
  • iOS - 解压ipa包中的Assert.car文件
  • 【Jmeter】配置不同业务请求比例,应对综合场景压测
  • TCP拥塞控制详解 | 1. 概述
  • 使用IPSEC VPN 在有防火墙的场景和有NAT转换的场景下实现隧道通信实验
  • Go和Java实现适配器模式
  • 接口相似数据结构复用率高?Apipost这招搞定!
  • 【零基础学Rust | 基础系列 | Hello, Rust】编写并运行第一个Rust程序
  • 代理模式.
  • BS框架说明
  • iOS——Block签名
  • Flutter 图片选取及裁剪
  • C语言每日一题:11.《数据结构》链表分割。
  • 记一次Oracle归档日志异常增长问题的排查过程
  • Java设计模式——类之间的关系
  • Dockerfile构建Redis镜像
  • C高级DAY2
  • Linux 服务管理
  • 问题记录 1 页面初始化触发el-form必填校验
  • 后端整理(JVM、Redis、反射)
  • 1. CUDA中的grid和block
  • 宝存科技企业级固态硬盘解决方案助力企业应用性能提升
  • 《练习100》31~35
  • 额外题目第4天|132 673 841 127 684 657
  • HTTP 状态码的分类和含义
  • Linux Bridge(网桥)