Vue项目之模糊搜索

Input模糊搜索

例子:
在这里插入图片描述
说明:在输入框中输入内容,显示模糊搜索,文字并高亮

1. html

<view class="wishView-style-content-search-contant" v-if="textValue.length === 0 ? false : true && textShow && inputValue">
	<view class="wishView-style-content-search-contant-item" v-for="(item,cellIndex) in textValue" :key="cellIndex" @click="SearchHuaTiList(item)">
		<view class="wishView-style-content-search-contant-item-two">
			<view class="wishView-style-content-search-contant-item-text">
				<span>{{item.type_name.slice(0,item.type_name.toLowerCase().indexOf(inputValue.toLowerCase()))}}</span>
				<span style="color:#0D8D5E">{{item.type_name.slice(item.type_name.toLowerCase().indexOf(inputValue.toLowerCase()),item.type_name.toLowerCase().indexOf(inputValue.toLowerCase())+inputValue.length)}}</span>
				<span>{{item.type_name.substr(item.type_name.toLowerCase().indexOf(inputValue.toLowerCase())+inputValue.length)}}</span>
			</view>
		</view>
	</view>
</view>

2. css

.wishView-style-content-search-contant {
		width: 100%;
		height: auto;
		background: #FFFFFF;
		box-shadow: 0px 0px 67px 0px rgba(60, 63, 79, 0.1);
		border-radius: 7px;
		position: absolute;
		top: 42px;
		z-index: 2;
	}

	.wishView-style-content-search-contant-item {
		width: 100%;
		height: 45px;
		display: flex;
		justify-content: center;
		cursor: pointer;
		margin: 5px 0;
	}

	.wishView-style-content-search-contant-item-two:hover {
		background-color: #F7F8FA !important;
	}

	.wishView-style-content-search-contant-item-two {
		width: 95%;
		display: flex;
		align-items: center;
		border-radius: 4px;
	}

	.wishView-style-content-search-contant-item-icon {
		width: 13px;
		height: 13px;
		display: flex;
		align-self: center;
		margin-left: 13px;
	}

	.wishView-style-content-search-contant-item-icon image {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}

	.wishView-style-content-search-contant-item-text {
		width: auto;
		height: 17px;
		font-size: 12px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		display: flex;
		align-self: center;
		margin-left: 10px;
	}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中,可以通过使用filterable属性来实现下拉框的模糊搜索功能。在引用\[1\]中的示例代码中,可以看到在el-select标签上添加了filterable属性,这样就可以在下拉框中输入关键字进行模糊查询了。同时,还可以使用v-model.trim来过滤输入的空格,以及clearable属性来实现清空输入内容的功能。在引用\[2\]中的示例代码中,el-autocomplete标签也可以实现类似的功能,通过fetch-suggestions属性来获取模糊搜索的建议列表。在methods方法中,可以编写querySearchGroup方法来处理模糊搜索的逻辑,通过传入的queryString参数进行搜索,并通过回调函数cb返回搜索结果。selectGroup方法可以在选择某个选项时获取选项的值。groupListMe方法可以用来获取下拉框的选项列表,可以通过发送请求获取数据,并将数据处理成选项列表的格式。clearSearch方法可以用来清空自动显示列表。综上所述,通过使用filterable属性和相关的方法,可以实现Vue下拉框的模糊搜索功能。 #### 引用[.reference_title] - *1* [vue下拉框可输入关键字进行模糊查询](https://blog.csdn.net/weixin_45470697/article/details/121992390)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [elementui,vue项目开发中el-select支持模糊搜索【下拉选择框支持模糊搜索】](https://blog.csdn.net/weixin_38483133/article/details/121009022)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值