uni-app使用uView的search搜索组件踩坑

场景:在开发后H5移动端项目时,使用uView的search搜索组件时遇到这样一个问题,search组件在安卓系统下显示正常,在ios系统下会显示出手机自带的搜索图标,与search组件的图标有冲突,两个图标会同时显示出来

解决:利用uni-app自己的input输入框,自己修改样式,手动加上搜索图标和清除图标,图标是外部引入的阿里图标

【注意】:不要给input输入框加上confirm-type=“search”,否则在ios系统下,还是会出现手机自带的搜索图标,和输入框的图标重复了

具体代码如下:

<template>
	<view style="display: flex; justify-content: space-between">
		<view class="input-wrap" slot="default">
			<text class="iconfont icon-sousuo"></text>
			<input 
				class="uni-input" 
				placeholder-style="color:#999;" 
				placeholder="请输入搜索内容" v-model="searchValue"
				@confirm="searchRes" 
				@input="inputChange" 
				@focus="focusSearch" 
				focus 
			/>
			<text class="iconfont icon-igw-f-clean" v-if="searchValue" @tap.stop="clearWords"></text>
		</view>
		<view class="cancel-button" @tap="cancel">取消</view>
	</view>
</template>
data() {
    return {
      searchValue: "",
      currentPage: 1,
      pageSize: 10,
      showRes: false,
    };
 },
methods: {
	clearWords() {
      let vm = this;

      vm.searchValue = "";
      vm.inputChange();
    },
    inputChange() {
      let vm = this;

      vm.getNumber();
      return new Promise((resolve, reject) => {
        vm.$req
          .doRequest({
            alias: "dcs-search-globalSearch",
            query: {
              keyword: vm.searchValue,
              pageNum: 1,
              pageSize: 10,
              type: "0",
            },
          })
          .then((res) => {
            if (res.code == 0) {
              if (vm.$refs.searchKeyword) {
                vm.$refs.searchKeyword.searchList = res.data.filter(
                  (item) => item.title.length > 0
                );
              }
            }
            return resolve(res.data);
          });
      });
    },
}
<style scoped lang="less">
	.input-wrap {
		width: 80%;
		margin: 42rpx 0 10rpx 28rpx !important;
		background: #f7f7f7;

		padding-left: 24rpx;
		display: flex;
		align-items: center;
		height: 80rpx;
		border-radius: 10rpx;

		/deep/ uni-input {
			font-size: 28rpx;
			width: 446rpx;
		}

		.icon-sousuo {
			font-size: 40rpx;
			font-weight: bold;
			margin-right: 20rpx;
		}

		.icon-igw-f-clean {
			font-size: 32rpx;
			margin-left: 16rpx;
			color: #bfbfbf;

		}
	}
</style>
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值