【uni-app】实现搜索框、历史记录等详细操作

Uni-app实现搜索框、历史记录传值、点击历史记录跳转页面等操作

input输入框:官网教程

v-model 参数:是一个用于实现双向数据绑定的指令。它允许将表单元素的值与Vue实例的数据对象属性进行关联,从而实现数据的同步更新。

使用v-model指令绑定表单元素的值。例如代码这里的<input type="text" value="" placeholder="搜索" v-model="keyword" @confirm="searchAction" />,这里将input元素的值绑定到了实例的keyword属性上。

网页代码

<template>
	<view>
		<view class="form">
			<view class="form-input">
                <!-- 可代替使用uniapp扩展组件的uni-icons 具体在https://uniapp.dcloud.net.cn/component/uniui/uni-icons.html
				-->
				<image src="../../static/images/icon-search.png" mode="widthFix"></image>
				<input type="text" value="" placeholder="搜索" v-model="keyword" @confirm="searchAction" />
			</view>
			<view class="cancel" @click="navigateBack">取消</view>
		</view>
        <view class="history">
			<view class="history-head">
				<text>搜索历史</text>
				<image src="../../static/images/icon-trash.png" mode="widthFix" @click="cleanHistory"></image>
			</view>
			<view class="history-list">
				<scroll-view v-for="item in historyList" @click="navigateToDetail(item)">
					{
  
  { item }}
				</scroll-view>
			</view>
		</view>
	</view>
</template>

style样式(自由发挥)

一定要加lang=“scss”,这样才可以完成嵌套样式操作

<style lang="scss" scoped>
	.form {
   
   
		background: white;
		display: flex;
		align-items: center;
		padding: 30rpx;

		.cancel {
   
   
			color: #666;
			margin-left: 20rpx;
			font-size: 28rpx;
		}
	}

	.form-input {
   
   
		display: flex;
		align-items: center;
		flex: 1;
		background-color: #f5f5f5;
		border-radius: 80rpx;
		padding: 0 10rpx;

		image {
   
   
			display: block;
			width: 36rpx;
			margin: 0 20rpx;
			flex-shrink: 0;
		}

		input {
   
   
			display: block;
			flex: 1;
			font-size: 28rpx;
			color: black;
			height: 70rpx;
			line-height: 70rpx;
		}
	}

	.history {
   
   
		background: white;
		padding:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值