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>
相关推荐
次顶级1 天前
表单多文件上传和其他参数处理
前端·javascript·html
why技术1 天前
我拿到了腾讯QClaw的内测码,然后沉默了。
前端·后端
小一梦1 天前
宝塔面板单域名部署多个 Vue 项目:从路径冲突到完美共存
服务器·javascript·vue.js
谪星·阿凯1 天前
XSS漏洞解析博客
前端·web安全·xss
ole ' ola1 天前
lambda表达式
java·前端·jvm
wefly20171 天前
无需安装、开箱即用!m3u8live.cn 在线 HLS 播放器,调试直播流效率翻倍
前端·后端·python·前端开发工具·后端开发工具
UXbot1 天前
为什么 AI 正在重新定义 UI 设计工具的入门门槛
前端·人工智能·低代码·ui·交互·ai编程·ux
柳杉1 天前
两款惊艳的 WebGL 开源项目推荐
前端·javascript·数据可视化
给算法爸爸上香1 天前
web网页显示点云
前端·3d·web·点云
IT_陈寒1 天前
React组件性能翻倍的5个冷门技巧,90%的开发者不知道!
前端·人工智能·后端