uni-app搜索-历史记录

2023-11-15

效果图
在这里插入图片描述

<template>
	<view>
		<!-- 搜索框 -->
		<view class="search">
			<view style="display: flex;align-items: center;">
				 <!-- @confirm="search" 点击 -->
				<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 @click="model(item,index)">{{ item }}</text>
					<text @click="del(item,index)" style="color: red;" >&nbsp; x</text>
				</view>
			</view>
		</view>
		<!-- 搜索历史 -->
	</view>
</template>

<script>
export default {
	data() {
		return {
			inputValue: '',
			searchHistoryList: [] //搜索出来的内容
		};
	},
	methods: {
		model(item,index){
			this.inputValue = item
		},
		del(item,index){
			this.searchHistoryList.splice(0,1)
		},
		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 lang='scss'>
	@import "search.scss";
</style>



.search {
	width: 100%;
	height: 30rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	box-sizing: border-box;
	padding: 2rpx 6rpx;
	margin-top: 20rpx;
	.searchInput {
		background-color: #f8f9fa;
		width: 220rpx;
		margin-left: 5rpx;
	}
}

.searchHistory {
	width: 100%;
	margin-top: 16rpx;
	.searchHistoryItem {
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		view {
			/* width: 50px; */
			height: 20rpx;
			background: #f0f0f0;
			padding: 4rpx;
			margin: 6rpx 5rpx;
		}
	}
}
	.main_classify{
		background: white;
		.main_under_classify{
			.li{
				height: 124rpx;
				border-bottom: 2rpx #999999 solid;
				padding: 20rpx 28rpx;
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;
				image{
					width: 116rpx;
					height: 110rpx;
					border-radius: 50%;
					margin-right: 20rpx;
					margin-top: 6rpx;
				}
				.li_content{
					width: 254rpx;
					.title{
						display: block;
						font-weight: 800;
						font-size: 28rpx;
					}
					text{
						line-height: 40rpx;
					}
					.zhiwei{
						color: #666666;
					}
					.heng{
						color: #999999;
					}
				}
				.li_end{
					padding: 0rpx 40rpx;
					width: 140rpx;
					height: 52rpx;
					border: 1rpx solid red;
					border-radius: 50rpx;
					display: flex;
					justify-content: space-between;
					margin-top: 36rpx;
					.jia{
						width: 24rpx;
						height: 24rpx;
						margin-top: 16rpx;
					}
					.erji{
						width: 42rpx;
						height: 42rpx;
					}
				}
			}
		}
	}




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

uni-app搜索-历史记录 的相关文章

  • PyTorch报错insufficient shared memory (shm)

    报错 ERROR Unexpected bus error encountered in worker This might be caused by insufficient shared memory shm ERROR Unexpec
  • 高并发分布式架构演进

    架构演进过程如下 单机架构 第一次演进 Tomcat与数据库分开部署 第二次演进 引入本地缓存和分布式缓存 第三次演进 引入反向代理实现负载均衡 第四次演进 数据库读写分离 第五次演进 数据库按业务分库 第六次演进 把大表拆分为小表 第七次
  • 哈工大计算机系统大作业

    哈工大计算机系统大作业 摘要 本文主要阐述在Linux系统下hello程序的生命周期 了解hello程序从hello c经过预处理 编译 汇编 链接生成可执行文件的全过程 结合课本的知识详细阐述计算机系统是如何对hello进行进程管理 存储

随机推荐

  • git commit 提交失败

    git commit 之后提示 原因 对项目进行git 操作的时候 会调用到pre commit的插件 它对代码风格进行检查 不符合规范则取消commit 操作 导致无法push 解决方案 方案一 git commit no verify
  • 打包aab教程,模拟器安装aab教程

    一 aab 打包 Android App Bundle aab 是谷歌新的安卓安装文件 其实也就是根据 cpu 架构和语言等 切分多个 apk 以减少包体体积 aab 打包有以下两种方式 AS 打包 Android Studio 打包 类型
  • Stack的三种含义

    学习编程的时候 经常会看到stack这个词 它的中文名字叫做 栈 理解这个概念 对于理解程序的运行至关重要 容易混淆的是 这个词其实有三种含义 适用于不同的场合 必须加以区分 含义一 数据结构 stack的第一种含义是一组数据的存放方式 特
  • 高通 Msm835平台充电功能的开发与调试

    目录 平台充电相关代码 835平台kernel充电相关代码 关机充电的系统相关代码 835平台UEFI 充电相关代码 835平台电池曲线 电池曲线大体内容如下 kernel 电池曲线的提交 XBL 关于充电曲线的提交 充电相关调试方法 充电
  • js逆向学习路线指南

    1 js基础教程 耗时2个星期 2个月 视基础而定 主要掌握用js进行程序设计 以及dom相关的知识 反复看 反复编程 并做好笔记 教程 https wangdoc com javascript index html 2 开始进行实战 多看
  • LeetCode 86. 分隔链表 Partition List(C语言)

    题目描述 给定一个链表和一个特定值 x 对链表进行分隔 使得所有小于 x 的节点都在大于或等于 x 的节点之前 你应当保留两个分区中每个节点的初始相对位置 示例 输入 head 1 gt 4 gt 3 gt 2 gt 5 gt 2 x 3
  • 【Dubbo】Dubbo(一)为什么使用Dubbo?

    Dubbo Dubbo是一款Java RPC框架 如何将应用打包并部署到服务器上 之前的单一应用架构 可以部署到多个服务器上 每次修改或扩展某一处功能都要将整个应用重新打包并部署到多台服务器上 协同开发时都改这一个应用 不利于开发与维护 当
  • 解决PyCharm ImportError: No module named tensorflow 详解

    运行 TensorFlow MNIST 实验程序时出错 报错原因 所用到的python解释器和我们当前PyCharm所用的python解释器不一致说导致 故解决方案 将PyCharm的解释器更改为TensorFlow下的python解释器
  • 源码分析shiro认证授权流程

    1 shiro介绍 Apache Shiro是一个强大易用的Java安全框架 提供了认证 授权 加密和会话管理等功能 认证 用户身份识别 常被称为用户 登录 授权 访问控制 密码加密 保护或隐藏数据防止被偷窥 会话管理 每用户相关的时间敏感
  • Qt中的私有信号

    一 什么是Qt私有信号 直接引用Qt文档中的描述 二 私有信号的作用 私有信号只能被响应 不能被用户代码来发射 emit 这是一种对某些信号的权限控制 也就是用户代码没有权力 发号施令 只能由Qt的类来发射 防止信号被 仿造 三 是否可以用
  • python网络爬虫--练习

    一 爬取王者荣耀英雄信息 单页 import json import pymysql import requests from lxml import etree def get heros url response requests ge
  • Linux中执行shell脚本

    在Linux系统下运行 sh文件有三种方法 比如我在root目录下有个test sh文件 第一种 在任何路径下 输入该文件的绝对路径 root test sh就可执行该文件 当然要在权限允许情况下 chmod 777 test sh tes
  • MATLAB二维绘图(一)使用plot函数进行简单绘图

    MATLAB二维绘图 一 使用plot函数进行简单绘图 1 使用plot绘制一个简单的图形 示例 单个参数绘图 clear clc close all t 1 200 y sin t pi 100 plot y t会默认从1开始间隔为1 结
  • 3dmax KeyError: ‘ Alphabet_S‘

    python opengl加载3d模型 报错 原因 mtl文件的name改了 更新一下就可以了 KeyError Alphabet S
  • QGIS-环境配置

    学习笔记 主要用于记录学习过程 及解决问题 如有侵权 请联系我 前言 本人是一名在校学生 应学校要求 学习QT QGIS 进行简单的遥感应用实现 一 学习环境 Windows10 VS2022 QT5 14 2 QGIS3 22 14 二
  • 蓝桥杯——《123》——python组十二届国赛真题

    题目描述 小蓝发现了一个有趣的数列 这个数列的前几项如下 1 1 2 1 2 3 1 2 3 4 小蓝发现 这个数列前 1 项是整数 1 接下来 2 项是整数 1 至 2 接下来3 项是整数 1 至 3 接下来 4 项是整数 1 至 4 依
  • iPhone/iPad如何与Windows10互传文件?

    本文提供共享文件夹的方式实现 例如在win10 D盘新建一个文件夹apple 右键属性 先后在 共享 S 高级共享 D 中设置 点击共享 S 添加Guest 权限设为读取 写入 之后依次点击共享 H 完成 D 按钮 点击高级共享 结果为下图
  • 4.11+4.12实习日志

    1 Qt帮助文档路径 Qt帮助文档路径 E Qt Qt5 9 9 5 9 9 mingw53 32 bin assistant exe 2 对象树 2 1 当创建的对象在堆区时候 如果指定的父亲是QObject派生下来的类或者QObject
  • SpringBoot返回json数据

    1 pom文件
  • uni-app搜索-历史记录

    效果图