最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue3+Ant?design?實(shí)現(xiàn)Select下拉框一鍵全選/清空功能

 更新時(shí)間:2024年05月28日 10:49:49   作者:℡52Hz  
在做后臺(tái)管理系統(tǒng)項(xiàng)目的時(shí)候,產(chǎn)品增加了一個(gè)在Select選擇器中添加一鍵全選和清空的功能,他又不讓在外部增加按鈕,其實(shí)如果說(shuō)在外部增加按鈕實(shí)現(xiàn)全選或者清空的話,功能比較簡(jiǎn)單的,下面給大家分享Vue3+Ant?design?實(shí)現(xiàn)Select下拉框一鍵全選/清空功能,需要的朋友可以參考下

最近在做后臺(tái)管理系統(tǒng)項(xiàng)目的時(shí)候,產(chǎn)品增加了一個(gè)讓人非??鄲赖男枨?,讓在Select選擇器中添加一鍵全選和清空的功能,剛開始聽(tīng)到的時(shí)候真是很懵,他又不讓在外部增加按鈕,其實(shí)如果說(shuō)在外部增加按鈕實(shí)現(xiàn)全選或者清空的話,功能相對(duì)來(lái)說(shuō)還是比較簡(jiǎn)單的。咱也是沒(méi)辦法啊公司的牛馬,只能按照需求來(lái)修改了。好在通過(guò)查找了資料自己又進(jìn)行了總結(jié)之后,實(shí)現(xiàn)了讓人惱火的需求,因?yàn)樵诓檎屹Y料的時(shí)候發(fā)現(xiàn)對(duì)于這一塊的知識(shí)點(diǎn),網(wǎng)上的還是少之又少的,基本上都是vue2的方式,所以咱既然已經(jīng)實(shí)現(xiàn)了,就分享給大家一起共享咯。

一、搭建頁(yè)面

在項(xiàng)目中安裝和引用ant design組件這里就不在細(xì)說(shuō)了,前面的很多案例中都有講解這一塊,不會(huì)的小伙伴可以進(jìn)行查看即可,當(dāng)然去ant design官網(wǎng)也有這些操作哦。

<template>
    <div class="test">
        <a-form-item label="營(yíng)運(yùn)單位" style="width: 16vw; margin: 15px">
          <a-select
            mode="multiple"
            :max-tag-count="1"
            allowClear
            v-model:value="valueGlc"
            @change="changeUnit"
            :options="optionsGlc"
          >
            <template #maxTagPlaceholder="omittedValues">
              <span class="allSelsct" v-if="optionsGlc.length === omittedValues.length + 1">全選</span>
              <span v-else>+ {{ omittedValues.length }} ...</span>
            </template>
            <!-- 全選---這里就是實(shí)現(xiàn)一鍵全選和清空的細(xì)節(jié)操作 -->
            <template #dropdownRender="{ menuNode: menu }">
              <v-nodes :vnodes="menu" />
              <a-divider style="margin: 4px 0" />
              <div style="padding: 4px 8px; margin-left: 50px; cursor: pointer" @mousedown="e => e.preventDefault()">
                <a-button type="link" @click="selectAll">全選</a-button>
                <a-button type="link" @click="clearAll">清空</a-button>
              </div>
            </template>
          </a-select>
        </a-form-item>
    </div>
</template>
<script setup>
//所選擇的營(yíng)運(yùn)單位
const valueGlc=ref('')
//營(yíng)運(yùn)單位選項(xiàng)列表
const optionsGlc=ref([])
//下拉菜單組件不可少,不然后續(xù)不顯示菜單
const VNodes = (_, { attrs }) => {
  return attrs.vnodes
}
//選擇營(yíng)運(yùn)單位事件
const changeUnit=()=>{}
// 一鍵全選
const selectAll=()=>{}
// 一鍵清空
const clearAll=()=>{}
</script>
<style lang='less' scoped>
.test{}
</style>

二、獲取select菜單中的數(shù)據(jù)

提示: 在這里獲取數(shù)據(jù)是使用了公司封裝后的框架

<script setup>
//來(lái)源于封裝后的數(shù)據(jù)地址--僅供參考
import { selectorRoadDeptLists } from '@/api/tjfx.js'
//所選擇的營(yíng)運(yùn)單位
const valueGlc=ref('')
//營(yíng)運(yùn)單位選項(xiàng)列表
const optionsGlc=ref([])
//下拉菜單組件不可少,不然后續(xù)不顯示菜單
const VNodes = (_, { attrs }) => {
  return attrs.vnodes
}
//選擇營(yíng)運(yùn)單位事件
const changeUnit=()=>{}
// 一鍵全選
const selectAll=()=>{}
// 一鍵清空
const clearAll=()=>{}
// 獲取下拉框數(shù)據(jù)-營(yíng)運(yùn)單位
const getOptionsGlc = () => {
  return new Promise((resolve, reject) => {
    selectorRoadDeptLists()
      .then(res => {
        if (res.code === 200 && res.data) {
          res.data.forEach((item, index) => {
            optionsGlc.value.push({
              value: item.code,
              code: item.code,
              label: item.name
            })
            valueGlc.value.push(item.code)
          })
        }
      })
  })
}
onMounted(() => {
    getOptionsGlc()
})

三、一鍵全選

在操作完以上的步驟后,select中已經(jīng)有對(duì)應(yīng)的數(shù)據(jù)了,但是最重要的步驟還未實(shí)施,下面是實(shí)現(xiàn)一鍵全選的代碼

// 一鍵全選
const selectAll=()=>{
    valueGlc.value = optionsGlc.value.map(option => option.value)
}

四、一鍵清空

// 一鍵清空
const clearAll=()=>{
    valueGlc.value = []
}

五、詳細(xì)代碼

以上就是實(shí)現(xiàn)一鍵全選和一鍵清空的詳細(xì)步驟啦,沒(méi)看懂的小伙伴最后附上全部代碼

<template>
    <div class="test">
        <a-form-item label="營(yíng)運(yùn)單位" style="width: 16vw; margin: 15px">
          <a-select
            mode="multiple"
            :max-tag-count="1"
            allowClear
            v-model:value="valueGlc"
            @change="changeUnit"
            :options="optionsGlc"
          >
            <template #maxTagPlaceholder="omittedValues">
              <span class="allSelsct" v-if="optionsGlc.length === omittedValues.length + 1">全選</span>
              <span v-else>+ {{ omittedValues.length }} ...</span>
            </template>
            <!-- 全選---這里就是實(shí)現(xiàn)一鍵全選和清空的細(xì)節(jié)操作 -->
            <template #dropdownRender="{ menuNode: menu }">
              <v-nodes :vnodes="menu" />
              <a-divider style="margin: 4px 0" />
              <div style="padding: 4px 8px; margin-left: 50px; cursor: pointer" @mousedown="e => e.preventDefault()">
                <a-button type="link" @click="selectAll">全選</a-button>
                <a-button type="link" @click="clearAll">清空</a-button>
              </div>
            </template>
          </a-select>
        </a-form-item>
    </div>
</template>
<script setup>
import { selectorRoadDeptLists } from '@/api/tjfx.js'
//所選擇的營(yíng)運(yùn)單位
const valueGlc=ref('')
//營(yíng)運(yùn)單位選項(xiàng)列表
const optionsGlc=ref([])
//下拉菜單組件不可少,不然后續(xù)不顯示菜單
const VNodes = (_, { attrs }) => {
  return attrs.vnodes
}
//選擇營(yíng)運(yùn)單位事件
const changeUnit=()=>{}
// 一鍵全選
const selectAll=()=>{
    valueGlc.value = optionsGlc.value.map(option => option.value)
}
// 一鍵清空
const clearAll=()=>{
    valueGlc.value = []
}
// 獲取下拉框數(shù)據(jù)-營(yíng)運(yùn)單位
const getOptionsGlc = () => {
  return new Promise((resolve, reject) => {
    selectorRoadDeptLists()
      .then(res => {
        if (res.code === 200 && res.data) {
          res.data.forEach((item, index) => {
            optionsGlc.value.push({
              value: item.code,
              code: item.code,
              label: item.name
            })
            valueGlc.value.push(item.code)
          })
        }
      })
  })
}
onMounted(() => {
    getOptionsGlc()
})
</script>
<style lang='less' scoped>
.test{}
</style>

到此這篇關(guān)于Vue3+Ant design 實(shí)現(xiàn)Select下拉框一鍵全選/清空的文章就介紹到這了,更多相關(guān)Vue3 Ant design下拉框全選內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue中如何優(yōu)雅的捕獲 Promise 異常詳解

    Vue中如何優(yōu)雅的捕獲 Promise 異常詳解

    這篇文章主要為大家介紹了Vue中如何優(yōu)雅的捕獲 Promise 異常詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • vue3 文檔梳理快速入門

    vue3 文檔梳理快速入門

    vue3之所以受廣大袁友的喜歡,優(yōu)點(diǎn)必不可少呀,比如:可以監(jiān)聽(tīng)動(dòng)態(tài)新增的屬性;可以監(jiān)聽(tīng)刪除的屬性 ;可以監(jiān)聽(tīng)數(shù)組的索引和 length 屬性;下面文章小編就來(lái)向大家介紹vue3,感興趣的小伙伴不要錯(cuò)過(guò)奧
    2021-09-09
  • Vue指令的學(xué)習(xí)

    Vue指令的學(xué)習(xí)

    這篇文章主要介紹了Vue指令,Vue官網(wǎng)一共有提供了14個(gè)指令,下面我們就來(lái)詳細(xì)講解每一個(gè)指令的詳細(xì)內(nèi)容,需要的朋友可以參考一下
    2021-10-10
  • vue實(shí)現(xiàn)綁定事件的方法實(shí)例代碼詳解

    vue實(shí)現(xiàn)綁定事件的方法實(shí)例代碼詳解

    這篇文章主要介紹了vue實(shí)現(xiàn)綁定事件的方法實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-06-06
  • vue 實(shí)現(xiàn)上傳組件

    vue 實(shí)現(xiàn)上傳組件

    雖然前端UI框架大都提供文件上傳的組件,以及很多插件可供選擇,工作中可能不需要我們手寫一個(gè)上傳組件,但是從零封裝組件對(duì)學(xué)習(xí)是很有助益的。下文為大家介紹使用Vue3+TypeScript實(shí)現(xiàn)的一個(gè)文件上傳的功能,目前只實(shí)現(xiàn)上傳等基本功能,后續(xù)會(huì)逐漸對(duì)功能進(jìn)行擴(kuò)展
    2021-05-05
  • 詳解Vue路由開啟keep-alive時(shí)的注意點(diǎn)

    詳解Vue路由開啟keep-alive時(shí)的注意點(diǎn)

    這篇文章主要介紹了詳解Vue路由開啟keep-alive時(shí)的注意點(diǎn),非常具有實(shí)用價(jià)值,有興趣的朋友可以了解一下
    2017-06-06
  • Vue實(shí)現(xiàn)PopupWindow組件詳解

    Vue實(shí)現(xiàn)PopupWindow組件詳解

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)PopupWindow組件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • 在Vue中引入SVG圖標(biāo)的多種實(shí)現(xiàn)方案

    在Vue中引入SVG圖標(biāo)的多種實(shí)現(xiàn)方案

    SVG圖標(biāo)集錦是一個(gè)豐富的資源庫(kù),包含了多個(gè)知名圖標(biāo)的集合,如bootstrap、feather、iconpark、ikonate和ionicons等,這些圖標(biāo)是為網(wǎng)頁(yè)開發(fā)設(shè)計(jì)的,具有高質(zhì)量和高度可定制性,在 Vue 項(xiàng)目中優(yōu)雅地引入 SVG 圖標(biāo)可通過(guò)多種方案實(shí)現(xiàn),下面小編給大家詳細(xì)說(shuō)說(shuō)
    2025-07-07
  • 使用Vue自定義數(shù)字鍵盤組件(體驗(yàn)度極好)

    使用Vue自定義數(shù)字鍵盤組件(體驗(yàn)度極好)

    最近做 Vue 開發(fā),因?yàn)橛胁簧夙?yè)面涉及到金額輸入,產(chǎn)品老是覺(jué)得用原生的 input 進(jìn)行金額輸入的話 體驗(yàn)很不好,于是自己動(dòng)手寫了一個(gè)使用Vue自定義數(shù)字鍵盤組件,具體實(shí)現(xiàn)代碼大家參考下本文
    2017-12-12
  • Vue中的字符串模板的使用

    Vue中的字符串模板的使用

    本篇文章主要介紹了Vue中的字符串模板的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05

最新評(píng)論

金堂县| 迭部县| 太保市| 都江堰市| 诏安县| 台南市| 绍兴县| 石嘴山市| 邵阳县| 平乐县| 黑河市| 曲靖市| 岱山县| 镇巴县| 盐边县| 晋州市| 昌吉市| 辉南县| 中江县| 景东| 吉安县| 墨竹工卡县| 宁武县| 南靖县| 贵阳市| 三原县| 沂水县| 海晏县| 宜城市| 修文县| 高台县| 玛曲县| 和田县| 青海省| 南平市| 永嘉县| 聊城市| 小金县| 廊坊市| 旌德县| 漠河县|