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>
相关推荐
wshzd3 小时前
LLM之Agent(120)|DeepSeek-Harness(二十七)Workflow 引擎与 Ralph 循环
前端·数据库·人工智能
涛涛ing3 小时前
React Compiler 1.0 之后,状态管理库正在被重新定义
前端
乘风gg3 小时前
出事了,AI 提效后,老板让我裁员20%
前端·后端·ai编程
Amos_Web3 小时前
Rspack 源码解析(三十二):rspack_plugin_runtime 如何抽象 chunk 加载与启动
前端
Amos_Web3 小时前
通过 Rspack 源码学 Rust(二):所有权、借用与 `&mut`
前端
计算机魔术师3 小时前
AI公司把「灾难性风险」写进招股书?Anthropic这5处反常
前端
西凉的悲伤3 小时前
Jsoup 库 HTML 解析详解
java·前端·html·jsoup
niucloud-admin3 小时前
NIUCLOUD PHP SAAS上门家政使用文档
前端·人工智能·ai编程
不一样的故事1264 小时前
Prompt 工程(Prompt Engineering)
前端·人工智能·python
ZoeLandia4 小时前
React08:自定义 Hook
开发语言·前端·react.js·typescript