uniapp picker-view 搜索选择框

<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. uniapp picker-view 搜索选择

    2024-07-23 09:22:05       18 阅读
  2. Ant Design Vue 搜索下拉

    2024-07-23 09:22:05       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-23 09:22:05       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-23 09:22:05       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-23 09:22:05       45 阅读
  4. Python语言-面向对象

    2024-07-23 09:22:05       55 阅读

热门阅读

  1. 前端面试题

    2024-07-23 09:22:05       15 阅读
  2. c 语言 中 是否有 unsigned 安;这种写法?

    2024-07-23 09:22:05       17 阅读
  3. Mojo模型与特征选择:数据科学中的智能筛选艺术

    2024-07-23 09:22:05       17 阅读
  4. PHP 数组排序算法对并行处理的影响

    2024-07-23 09:22:05       17 阅读
  5. Symbol

    2024-07-23 09:22:05       15 阅读
  6. DP学习——状态模式

    2024-07-23 09:22:05       17 阅读
  7. Gradle依赖报告:项目依赖树的X光机

    2024-07-23 09:22:05       18 阅读
  8. 推翻百年集论的三个定理

    2024-07-23 09:22:05       12 阅读
  9. 2710. 移除字符串中的尾随零

    2024-07-23 09:22:05       18 阅读
  10. AI学习指南机器学习篇-SOM的优缺点

    2024-07-23 09:22:05       15 阅读