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>
相关推荐
石小石Orz25 分钟前
星云SDK + 油猴:给LLM塑造肉身,陪伴你在每个网页
前端·人工智能
2601_9637713728 分钟前
10 Best PHP Media CMS and Scripts for Web Creators in 2026
开发语言·前端·php
VaJoy1 小时前
全面革新⚡️ Vue 3.6 项目工程的基础实现
前端·vue.js
苍何1 小时前
耗时 7 天,我们开源了腾讯 WorkBuddy 实战蓝皮书(建议收藏)
前端·后端
大家的林语冰2 小时前
😭 Electron 麻了,Deno 直接支持二进制应用,无需第三方桌面应用框架!
前端·javascript·node.js
Ivanqhz2 小时前
NFM(神经因子分解机)
开发语言·javascript·人工智能·算法·蓝桥杯
Damai2 小时前
DOMPurify 完整介绍
前端·面试
随风一样自由2 小时前
【前端+跨域】跨域问题全面解析与解决方案指南
前端·跨域
小帅不太帅2 小时前
我随手发了几张截图,白拿了一个月 AI 顶配会员
前端·github
36岁的我开始学习打篮球2 小时前
外规内化技术架构
前端