您的位置:首页 > 教育 > 锐评 > uniapp picker-view 搜索选择框

uniapp picker-view 搜索选择框

2024/10/6 18:33:00 来源:https://blog.csdn.net/qq_45777315/article/details/140612520  浏览:    关键词: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>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com