vant 动态查询下拉菜单(可用)

动态查询item项

html 复制代码
<van-form @submit="onSubmit" ref="formRef">
    <Title title="企业信息" title-line title-size="19" class="ml-[18px] mb-[18px]"></Title>
    <van-cell-group inset class="py-[18px]">
      <div>
        <field-title title="所属企业" class="ml-4"></field-title>
        <van-field
            v-model="model.companyName"
            is-link
            readonly
            name="所属企业"
            placeholder="请选择所属企业"
            @click="showPicker = true"
            :rules="[{ required: true, message: '必填项' }]"
            @input="getCompanyList(model.companyName)"
        />
        <van-popup v-model:show="showPicker" position="bottom" :close-on-click-overlay="false">
          <div class="w-full text-center mt-4">选择企业</div>
          <van-search
              placeholder="输入企业名称"
              v-model="model.companyName"
              @search="onSearch"
              @update:model-value="getCompanyList"
          ></van-search>
          <van-picker
              :columns="options"
              @confirm="onConfirm"
              @cancel="handCancelPickerCompanyInfo"
          >
          </van-picker>
        </van-popup>
      </div>
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button  block type="primary" native-type="submit" :loading="loading" :disabled="loading">
        注册
      </van-button>
    </div>
  </van-form>
javascript 复制代码
  const model = ref({
    companyName: undefined,
    companyCode: undefined,
  })

  const showPicker = ref(false);
  
  const onConfirm = ({selectedOptions}) => {
    model.value.companyName = selectedOptions[0]?.text
    model.value.companyCode = selectedOptions[0]?.value;
    showPicker.value = false;
  };
  function onSearch(value) {
    getCompanyList(value)
  }
  const options = ref<any>([])
  const loading = ref(false)
  const loadingSearch = ref(false)

  function getCompanyList(value: string) {
    if (!value.length) {
      options.value = []
      return
    }
    loadingSearch.value = true
    getEnterpriseOptionApi(value).then((res) => {
      options.value = res.rows.map(item => ({text: item.label, value: item.value}))
      loadingSearch.value = false
    }).catch((err) => {
      loadingSearch.value = false
    })
  }
 function handCancelPickerCompanyInfo() {
   showPicker.value = false
   options.value = []
   model.value.companyName = undefined;
   model.value.companyCode = undefined;
 }
相关推荐
河西石头2 个月前
为微信小程序换皮肤之配置vant
vant·1024程序员节·微信小程序第三方ui·vant图标显示为方框·解决vant图标显示错误
Mr.史3 个月前
vant van-pull-refresh + van-list实现list列表支持搜索和下拉刷新
前端·vant
这孩子叫逆3 个月前
uni-app进行微信小程序开发,快速上手
微信小程序·vue3·uniapp·vant
wocwin4 个月前
Vue2移动端(H5项目)项目基于vant实现select单选(支持搜索、回显、自定义下拉label展示功能)
vue.js·vant·移动端·下拉选择·vant-ui·组件封装·select单选
小陈同学呦5 个月前
五分钟带你学会Vant 4的使用
前端·javascript·vant
ELNino_Thomas.Liang6 个月前
vant的dialog触发了其他overlay
前端·javascript·vue.js·html·vant
程楠楠&M6 个月前
vue3.0 + vant实现下拉刷新上拉加载
前端·javascript·vue.js·vant·上拉加载,下拉刷新
Ying(英子)6 个月前
在微信小程序中安装和使用vant框架
微信小程序·小程序·vant·全局使用vant·vant安装与使用·微信小程序入门·小程序安装vant
凡人修仙ing6 个月前
小程序使用vant weapp,官方快速上手教程npm构建报错
vant