Vant DropdownMenu 下拉菜单带搜索功能

Vant DropdownMenu 下拉菜单带搜索功能

效果图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
上代码:

 <van-dropdown-menu active-color="#E33737">
      <van-dropdown-item ref="dropdownItem">
        <template #title>
          <span>{{ dropdownItem.text }}</span>
        </template>
        <div class="dropdown_search">
          <van-search shape="round" v-model="searchValue" placeholder="请输入搜索关键词" @input="searchFun" />
        </div>
        <div class="dropdown_radio">
          <van-radio-group v-model="dropdownValue">
            <van-cell-group>
              <van-cell v-for="(item, index) in dropdownFilterActions" :key="index" :value="item.text" clickable center
                @click="onChangeSelect(item.value)">
                <template #right-icon>
                  <van-radio :name="item.value" />
                </template>
              </van-cell>
            </van-cell-group>
          </van-radio-group>
        </div>
      </van-dropdown-item>
    </van-dropdown-menu>
  data() {
    return {
      dropdownValue: '',
      dropdownItem: { text: '全部', value: '730' },
      searchValue: '',
      dropdownFilterActions: [], //过滤的数据
      dropdownActions: [ //原数据
        { text: '近一周', value: '7' },
        { text: '近一个月', value: '30' },
        { text: '近一年', value: '365' },
        { text: '全部', value: '730' }
      ]
      }
    }
  
  created() {
    this.dropdownFilterActions = this.dropdownActions
  },
  methods: {
    searchFun() {
      if (this.searchValue === '' || this.searchValue === null) {
        this.dropdownFilterActions = this.dropdownActions;
      } else {
        this.dropdownFilterActions = this.dropdownActions.filter(item => item.text.includes(this.searchValue))
      }
    },
    onChangeSelect(value) {
      this.dropdownItem = this.dropdownFilterActions.find(item => {
        return item.value === value;
      });
      this.searchValue = '';
      this.searchFun();
      this.$refs.dropdownItem.toggle()
      this.dropdownValue = value;
    },
}

<style lang="less" scoped>
.dropdown_search {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 99;
}

.dropdown_radio {
  :deep(.van-cell__value--alone) {
    text-align: center;
  }

  :deep(.van-radio__icon .van-icon) {
    border: unset;
    background: unset;
    border-color: unset;
    font-size: @-size-m;
  }

  :deep(.van-radio__icon--checked .van-icon) {
    color: @-color-primary;
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值