uniapp picker-view 搜索选择框

html 复制代码
<template>
  <view class="container">
    <input type="text" v-model="keyword" placeholder="输入关键词搜索" class="search-input" @input="handleSearch">
    <picker-view :value="value" @change="pickerChange">
      <picker-view-column>
        <view v-for="(item, index) in filteredOptions" :key="index" @click="xx(item)">{{ item }}</view>
      </picker-view-column>
    </picker-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      options: ['选项1', '选项2', '选项3', '选项4', '选项5', '选项22'],
      filteredOptions: ['选项1', '选项2', '选项3', '选项4', '选项5', '选项22'],
      value: [0], // 默认选中第一个选项
      keyword: ''
    };
  },
  methods: {
    handleSearch() {
      const keyword = this.keyword.trim().toLowerCase();
      if (keyword === '') {
        this.filteredOptions = [...this.options];
      } else {
        this.filteredOptions = this.options.filter(option =>
          option.toLowerCase().includes(keyword)
        );
      }
      // 搜索后,默认选中第一个匹配项
      this.value = [0];
    },
    pickerChange(e) {
      this.value = e.detail.value;
	  console.log(e)
    },
	xx(item){
		console.log(item)
	}
  }
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.search-input {
  width: 80%;
  margin-bottom: 20px;
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

picker-view {
  width: 80%;
  max-width: 400px;
  height: 200px;
  background-color: #f0f0f0;
  border-radius: 10px;
}

picker-view-column {
  flex: 1;
  text-align: center;
  line-height: 50px;
}
</style>
相关推荐
我命由我123451 小时前
React - 验证 Diffing 算法、key 的作用
javascript·算法·react.js·前端框架·html·html5·js
@PHARAOH3 小时前
HOW - Kratos 入门实践(二)- 概念学习
前端·微服务·go
We་ct7 小时前
LeetCode 77. 组合:DFS回溯+剪枝,高效求解组合问题
开发语言·前端·算法·leetcode·typescript·深度优先·剪枝
KerwinChou_CN7 小时前
什么是流式输出,后端怎么生成,前端怎么渲染
前端
爱上妖精的尾巴7 小时前
8-18 WPS JS宏 正则表达式-边界匹配
开发语言·javascript·正则表达式·wps·jsa
爱上妖精的尾巴7 小时前
8-20 WPS JS宏 正则表达式-懒惰匹配
服务器·前端·javascript
网络点点滴7 小时前
组件通信props方式
前端·javascript·vue.js
二十雨辰7 小时前
[小结]-线上Bug监控
前端·bug
前端技术7 小时前
【鸿蒙实战】从零打造智能物联网家居控制系统:HarmonyOS Next分布式能力的完美诠释
java·前端·人工智能·分布式·物联网·前端框架·harmonyos
CHU7290357 小时前
指尖践行环保——旧衣服回收小程序前端功能玩法详解
前端·小程序