Vant彈出列表多選輸入框下拉選擇代碼(可直接復(fù)制使用)
項(xiàng)目要做移動端,部分功能遷移過程中發(fā)現(xiàn),VantUI組件庫不支持原Element組件庫的部分功能,例如el-select 可以做到輸入的同時(shí)下拉選擇 下拉多選。
故需要手動改寫,分享記錄下代碼。
效果圖



代碼示例:
<script setup lang="ts">
import { ref,reactive,computed,watch,watchEffect,onMounted } from "vue";//各種API
import store from '../../store'
import router from '../../router'
import { useRouter } from 'vue-router';
const $router = useRouter();
onMounted(()=>{
getEstimateTime('estimateTime').then((res) => {
quickReplyList.value = res.data.map((v) => {
return { text: v.codeName };
});
quickReplyList.value.forEach((item,index) => {
item.value = index
});
});
getUserList('SHJS').then(res=>{
userAssignList.value = res.data
userAssignList.value.forEach((item,index) => {
item.text = item.userName
item.value = index
item.checked = false
});
})
})
const quickReplyList = ref([]);
function QuickReplySelect ({ selectedValues }) {
userAssignReply.value = quickReplyList.value[selectedValues].text
showPickerReply.value = false
};
const userAssign = ref([]);
const userAssignText = ref('');
const userAssignReply = ref('');
const userAssignList = ref([]);
const dialogShow = ref(false);
const showPickerCheckbox= ref(false);
const checkboxRefs = ref([]);
function toggle(index:number){
checkboxRefs.value[index].toggle();
};
function zhipaiSelect () {
let arr:any[] = [];
if(userAssign.value.length>0){
userAssign.value.forEach(it=>{
arr.push(userAssignList.value.find(item=>item.userId==it).userName)
})
}
userAssignText.value = arr.join()
showPickerCheckbox.value = false
};
function zhipaihandleSubmit() {
if(!userAssign.value){
showToast('請選擇處理人');
return
}
setAssign({
userIds:userAssign.value,//數(shù)組
label: userAssignReply.value
}).then((res) => {
showNotify({ type: 'success', message: '成功' });
dialogShow .value = false
userAssign.value = ''
userAssignReply.value = ''
});
}
</script>
<template>
<div class="detail-div">
<van-button round color="#169bd5" @click="dialogShow = true” style="width:98vw"
>認(rèn) 領(lǐng)</van-button>
<van-dialog v-model:show="dialogShow" title="測試下拉輸入框與彈窗選擇"
show-cancel-button @confirm="zhipaihandleSubmit" :before-close="onBeforeClose">
<van-field>
<template #input>
<van-field
v-model="userAssignText"
is-link
readonly
label="處理人"
placeholder="請選擇"
@click="showPickerCheckbox= true"
/>
</template>
</van-field>
<van-field v-if="currentRow.status==2">
<template #input>
<van-field
v-model="userAssignReply"
label="快捷回復(fù)"
placeholder="請輸入內(nèi)容"
/>
<van-button @click="showPickerReply= true" size="mini" icon="arrow-down" />
</template>
</van-field>
</van-dialog>
<van-popup v-model:show="showPickerReply" position="bottom">
<van-picker
title="快捷回復(fù)"
:columns="quickReplyList"
@confirm="QuickReplySelect"
@cancel="showPickerReply= false"
/>
</van-popup>
<!-- 彈窗多選列表 -->
<van-popup v-model:show="showPickerCheckbox" position="bottom">
<div style="display: flex;justify-content: space-between;height:44px;line-height:44px;">
<van-button style="border:none;color:#969799;" @click="showPickerCheckbox= false" size="normal">取消</van-button>
<span style="font-size:16px;font-weight:bold;">處理人</span>
<van-button style="border:none;color:#6398fb;" @click="zhipaiSelect" size="normal">確認(rèn)</van-button>
</div>
<van-checkbox-group v-model="userAssign" ref="checkboxGroup">
<van-cell
v-for="(item, index) in userAssignList"
clickable
:key="item"
:title="` ${item.userName}`"
@click="toggle(index)"
>
<template #right-icon>
<van-checkbox
:name="item.userId"
:ref="el => checkboxRefs[index] = el"
@click.stop
/>
</template>
</van-cell>
</van-checkbox-group>
</van-popup>
</div>
</template>總結(jié)
到此這篇關(guān)于Vant彈出列表多選輸入框下拉選擇的文章就介紹到這了,更多相關(guān)Vant彈出列表多選輸入框下拉選擇內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue項(xiàng)目啟動后沒有局域網(wǎng)地址問題
這篇文章主要介紹了vue項(xiàng)目啟動后沒有局域網(wǎng)地址問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09
教你用vue實(shí)現(xiàn)一個(gè)有趣的圍繞圓弧動畫效果
最近做的兩個(gè)項(xiàng)目都是關(guān)于vue的,做完整理一下,這篇文章主要給大家介紹了關(guān)于如何用vue實(shí)現(xiàn)一個(gè)有趣的圍繞圓弧動畫效果的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04
基于Vue+ECharts實(shí)現(xiàn)地圖展示與交互
這篇文章中,我將逐步介紹如何使用 Vue 和 ECharts 實(shí)現(xiàn)一個(gè)互動式的地圖展示組件,其中支持返回上一層地圖、點(diǎn)擊查看不同城市的詳細(xì)信息,以及根據(jù)數(shù)據(jù)動態(tài)展示不同的統(tǒng)計(jì)信息,感興趣的小伙伴跟著小編一起來看看吧2025-02-02
關(guān)于vue 結(jié)合原生js 解決echarts resize問題
這篇文章主要介紹了關(guān)于vue 結(jié)合原生js 解決echarts resize問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
el-select 點(diǎn)擊按鈕滾動到選擇框頂部的實(shí)現(xiàn)代碼
本文通過實(shí)例代碼給大家分享el-select 點(diǎn)擊按鈕滾動到選擇框頂部效果,主要代碼是在visibleChange在這個(gè)popper里面找到.el-select-dropdown__list,感興趣的朋友跟隨小編一起看看吧2024-05-05
vue實(shí)現(xiàn)可視化可拖放的自定義表單的示例代碼
這篇文章主要介紹了vue實(shí)現(xiàn)可視化可拖放的自定義表單的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03

