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>

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-file-picker是uni-app框架中的一个组件,用于在移动端应用中实现图片上传功能。通过该组件,用户可以选择图片并将其上传到服务器。 以下是使用uni-file-picker组件实现图片上传的步骤: 1. 在页面中引入uni-file-picker组件,并设置相关属性: ```html <template> <view> <uni-file-picker limit="1" ref="files" :auto-upload="false" @select="select" @delete="del" v-model="one"></uni-file-picker> <button @click="upload">上传图片</button> </view> </template> ``` 其中,limit属性用于限制选择图片的数量,ref属性用于获取组件实例,auto-upload属性设置为false表示不自动上传图片,@select和@delete分别是选择图片和删除图片时触发的事件,v-model用于双向绑定选择的图片。 2. 在页面的script标签中定义相关方法: ```javascript <script> export default { data() { return { one: [] // 存储选择的图片 } }, methods: { select(files) { // 选择图片时触发的方法 this.one = files }, del(files) { // 删除图片时触发的方法 this.one = files }, upload() { // 上传图片的方法 // 可以在这里调用接口将图片上传到服务器 console.log(this.one) } } } </script> ``` 在select方法中,将选择的图片赋值给one变量;在del方法中,将删除图片后的结果赋值给one变量;在upload方法中,可以调用接口将选择的图片上传到服务器。 通过以上步骤,就可以在uni-app中使用uni-file-picker组件实现图片上传功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值