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>
相关推荐
MaAidan20 分钟前
用 Agent 排查线上问题:SLS 日志分析 + DB/Redis 数据验证,一条链路搞清楚
前端·bootstrap·html
墨林陌35 分钟前
AI 热点日报(2026-11-03):美团发布 1.6 万亿参数国产大模型,四大厂商共推 AI 训练退出标准
前端
Moment41 分钟前
DeepSeek 发布新模型,直接把 Agent 联网搜索的门槛打下来了!
前端·后端
雪芽蓝域zzs43 分钟前
WebStorm Uniapp Support + Uniapp Tool + Uniappx Language Service讲解
vue.js·uni-app·webstorm
AI宇宙狂想家1 小时前
开源 AI 视频工具进化史:从难用到好用,OpenMontage 改了什么
开发语言·前端·人工智能·开源·ai创业·openmontage
Sailing1 小时前
🚀🚀【封闭结束7】Agent 为什么总是“失忆”?从长期记忆到上下文工程的生产实践
前端·人工智能·agent
OpenTiny社区1 小时前
AI 生成的 Vue 代码,终于能直接用了!
前端·vue.js·github
程序员大阳2 小时前
副队长JavaScript教程(67)-Ajax初识:背景、历史与核心概念
javascript·ajax·同步·异步·概念·背景·来是
程序员大阳2 小时前
副队长JavaScript教程(70)-Ajax同源策略与跨域
javascript·ajax·同源策略·跨越·corp
Ramble_Naylor2 小时前
Rust深度解读:高性能 Web 网关与 Axum 架构剖析
前端·架构·rust