uniapp搜索框

uniapp搜索框

<!-- 头部搜索框 -->
    <view class="Derinput">
      <view class="header">
        <db-search :logo="equipmentNo" @searchMsg="headerSearch" :btnShow="true" ref="search"></db-search>
      </view>
    </view>
    
   
   data(){
     return{
        equipmentNo: '',
     }
   },
   methods:{
     headerSearch(value) {
      console.log('value: ' + value);
      this.equipmentNo = value;
      this.getequipment();//列表数据接口
    },
   }
<style>
 .Derinput {
    .header {
      height: 46px;
      background: #ffffff;
      margin-bottom: 5px;
    }
  }
</style>

在这里插入图片描述

components----->db-search---->db-search.vue

<template>
  <view class="db-search" :style="!btnShow ? 'margin-right: 38rpx;' : ''">
    <!-- <image class="logo" :src="logo"></image> -->
    <input
      class="search-input"
      :class="{ noSearchBtn: !btnShow }"
      @focus="focusMsg"
      @input="inputMsg"
      v-model="textValue"
      type="text"
      placeholder="请输入设备号搜索"
      placeholder-class="placeholder-class"
      src="../../static/search.png"
    />
    <image class="search-icon" v-show="isMaskingShow" src="../../static/search.png"></image>
    <view class="search-btn" v-show="btnShow" @tap="searchMsg()">取消</view>
    <view class="db-search-btn" v-show="isMaskingShow"></view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      textValue: '',
    };
  },

  methods: {
    //输入监听
    inputMsg() {
      this.$emit('inputMsg', this.textValue);
      this.$emit('searchMsg', this.textValue);
    },
    //获得焦点时监听
    focusMsg() {
      this.$emit('focusMsg');
    },
    //点击搜索按钮监听
    searchMsg() {
      // this.$emit("searchMsg", this.textValue);
      uni.navigateBack({});
    },
    getLogo() {
      let logo = this.$storage.get('search-logo');
      return logo || '';
    },
  },

  props: {
    btnShow: {
      type: Boolean,
      default: false,
    },

    isMaskingShow: {
      type: Boolean,
      default: false,
    },

    logo: {
      type: String,
      default: `${uni.getStorageSync('logo-search')}`,
    },
  },
};
</script>

<style lang="scss">
.db-search {
  position: relative;
  display: flex;
  align-items: center;
  // background-color: #fff;
  height: 80rpx;
  .logo {
    width: 80rpx;
    height: 50rpx;
    margin-left: 38rpx;
  }
  .search-icon {
    position: absolute;
    right: 50rpx;
    width: 32rpx;
    height: 32rpx;
  }
  .placeholder-class {
    padding-left: 0px;
  }
  .search-input {
    flex: 1;
    margin-left: 38rpx;
    padding-top: 8rpx;
    padding-bottom: 8rpx;
    padding-left: 15px;
    background-color: #f8f8f8;
    border-radius: 8rpx;
    border-radius: 30rpx;
    &.noSearchBtn {
      // margin-right: 30rpx;
      border-radius: 30rpx;
    }
  }

  .search-btn {
    font-size: 28rpx;
    // font-weight: bold;
    width: 100rpx;
    text-align: center;
  }

  .db-search-btn {
    position: absolute;
    left: 100rpx;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: unset;
    z-index: 22;
  }
}

.placeholder-class {
  color: #999;
  font-size: 28rpx;
  padding-left: 20rpx;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在uniapp中实现搜索框功能,可以按照以下步骤进行操作: 1. 在搜索框的输入框中添加一个@input事件,用于监听输入框内容的变化。在这个事件中,可以通过e.target.value获取到输入框的值。 2. 在@input事件中,可以根据输入框的值进行相应的处理。例如,如果输入框的值为空,则可以清空搜索结果,并将相关的样式设置为未搜索状态。 3. 当用户点击搜索按钮或按下回车键时,可以触发一个方法(例如sou()),在这个方法中可以进行搜索操作。 4. 在搜索方法中,可以使用uni.navigateTo()方法跳转到搜索结果页,并将搜索关键字作为参数传递给搜索结果页。 5. 在搜索结果页中,可以通过uniCloud.database().collection().get()方法获取到相应的搜索结果数据,并进行渲染。 6. 根据搜索结果的情况,可以设置相应的样式和显示内容。例如,如果搜索结果是用户自己的信息,则可以隐藏加好友按钮。 通过以上步骤,就可以实现uniapp中的搜索框功能。请注意,以上步骤中的代码片段是根据提供的引用内容进行的推测,具体的实现方式可能会有所不同。 #### 引用[.reference_title] - *1* [uni-app实现搜索功能](https://blog.csdn.net/qq_60077855/article/details/125579597)[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^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [uniapp实现搜索功能详细步骤【前端开发】](https://blog.csdn.net/qq_52736131/article/details/122292730)[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^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值