国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uni-app微信小程序開(kāi)發(fā)自定義select下拉多選內(nèi)容篇

這篇具有很好參考價(jià)值的文章主要介紹了uni-app微信小程序開(kāi)發(fā)自定義select下拉多選內(nèi)容篇。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

歡迎點(diǎn)擊領(lǐng)取 -《前端開(kāi)發(fā)面試題進(jìn)階秘籍》:前端登頂之巔-最全面的前端知識(shí)點(diǎn)梳理總結(jié)

技術(shù)框架公司的選型:uni-app + uni-ui + vue3 + vite4 + ts

需求分析:微信小程序-uni-ui內(nèi)容
1、創(chuàng)建一個(gè)自定義的下拉,支持多個(gè)內(nèi)容的同時(shí)多選
2、定義好出入?yún)?shù),支持回顯內(nèi)容等
3、綁定對(duì)應(yīng)的v-model數(shù)據(jù)響應(yīng)

uni-app微信小程序開(kāi)發(fā)自定義select下拉多選內(nèi)容篇,vue3,vite,uni-app,uni-app,微信小程序,小程序

1、代碼信息
<template>
  <view tabindex="1" ref="customSelectRef" class="uni-select" @click.stop="handleClickDiv">
    <view>
      <template v-if="modelLabel.length">
        <span class="custom-tag" :key="index" v-for="(item, index) in modelLabel">
          <span>{{ item }}</span>
        </span>
      </template>
      <span class="custom-tag" v-if="modelLabel.length && checkList.length - maxLength > 0">
        + {{ checkList.length - maxLength }}
      </span>
      <span v-if="!modelLabel.length" class="cus_placeholder">{{ placeholder }}</span>
      <img
        class="icon-delete"
        v-if="modelLabel.length"
        @click.stop="handleRemove"
        :src="'../../static/icons/delete.png'"
      />
    </view>
    <transition>
      <view class="cus_select_background" ref="cusSelectDropdown" v-if="isShowDropdown" @click="handleMemory">
        <view class="cus_tabs" :key="index" v-for="(item, index) in cusDataListChecked">
          <template v-if="item.children">
            <view class="cus_tabs_title">{{ item.text }}</view>
            <view class="cus_tabs_body">
              <uni-data-checkbox
                mode="tag"
                :multiple="multiple"
                v-model="item.checkList"
                :localdata="item.children"
                @change="(val) => handleCheckedChange(val, item)"
              ></uni-data-checkbox>
            </view>
          </template>
        </view>
      </view>
    </transition>
    <view v-if="isShowDropdown" class="custom_mask"></view>
  </view>
</template>

<script setup lang="ts">
import { watch } from "vue";
import { toRaw } from "vue";
import { ref, onMounted, nextTick, onBeforeMount } from "vue";

const props = withDefaults(
  defineProps<{
    dataSource: any;
    modelValue?: any;
    placeholder?: string;
    multiple?: boolean;
    maxLength?: number;
  }>(),
  {
    multiple: true,
    dataSource: [],
    modelValue: [],
    maxLength: 3,
    placeholder: "請(qǐng)選擇",
  }
);

const emit = defineEmits(["update:modelValue", 'change']);

const customSelectRef = ref();

const cusSelectDropdown = ref();

const modelLabel = ref<Record<string, any>[]>([]);

const checkList = ref<string[]>([]);

const cusDataListChecked = ref<Record<string, any>[]>([]);

const isShowDropdown = ref<boolean>(false);

const isShowDownMemory = ref<boolean>(false);

const handleClickDiv = () => {
  isShowDropdown.value = isShowDownMemory.value ? true : !isShowDropdown.value;
  isShowDownMemory.value = false;
};

const handleMemory = () => {
  isShowDownMemory.value = true;
};

const handleCheckedChange = (e: Record<string, any>, row: Record<string, any>) => {
  const { data } = e.detail;
  row.checkLabel = data.map((opt) => opt.text);
  getModelVal();
};

const getModelVal = () => {
  const newValue = toRaw(cusDataListChecked.value);
  const newLabel = newValue.map((item) => item.checkLabel);
  const newModelVal = newValue.map((item) => item.checkList);
  const deconstructLabel = newLabel?.flat();
  const deconstructVal = newModelVal?.flat();
  modelLabel.value = deconstructLabel.slice(0, props.maxLength);
  checkList.value = deconstructVal;
  emit("update:modelValue", newModelVal);
};

const handleRemove = (e) => {
  modelLabel.value = [];
  checkList.value = [];
  if (isShowDropdown.value) {
    isShowDropdown.value = false;
  }
  if (props.multiple) {
    cusDataListChecked.value = addCheckProperties(props.dataSource);
  }
  emit("update:modelValue", []);
};

const addCheckProperties = (treeData) => {
  let result = [];
  result = JSON.parse(JSON.stringify(treeData));
  result.forEach((node) => {
    const child = node.children;
    node.checkList = [];
    node.checkLabel = [];
    if (child && child.length > 0) {
      addCheckProperties(child);
    }
  });
  return result;
};

const findTreeChecked = (treeData) => {
  const newLabel = [];
  const val = toRaw(props.modelValue);
  treeData.forEach((node, index) => {
    if (node.children?.length) {
      const child = node.children;
      const bool = child.some((opt) => {
        const isExist = val[index] && val[index].includes(opt.value);
        isExist ? newLabel.push(opt.text) : void null;
        return isExist;
      });
      if (bool) {
        node.checkLabel = newLabel;
        node.checkList = val[index];
      }
    }
  });
  return treeData;
};

watch(isShowDropdown, (newVal) => {
  emit('change', newVal, props.modelValue)
})

onBeforeMount(() => {
  if (props.multiple) {
    cusDataListChecked.value = addCheckProperties(props.dataSource);
  }
});

onMounted(async () => {
  await nextTick();
  if (props.multiple && props.modelValue.length) {
    cusDataListChecked.value = findTreeChecked(cusDataListChecked.value);
    getModelVal();
  }
});
</script>

<style lang="scss" scoped>
.uni-select {
  font-size: 14px;
  border: 1px solid #e5e5e5;
  box-sizing: border-box;
  border-radius: 4px;
  padding: 0 5px 0 10px;
  position: relative;
  display: flex;
  user-select: none;
  flex-direction: row;
  align-items: center;
  border-bottom: solid 1px #e5e5e5;
  width: 100%;
  flex: 1;
  height: 35px;
  position: relative;
}

.cus_placeholder {
  color: #6a6a6a;
  font-size: 12px;
}

.icon-delete {
  position: absolute;
  width: 18px;
  height: 18px;
  right: 5px;
  margin-top: 3.5px;
  z-index: 10;
}

.cus_select_background {
  width: 95vw;
  max-height: 260px;
  box-sizing: border-box;
  border-radius: 4px;
  font-size: 13px;
  color: #606266;
  background: #ffffff;
  border: 1px solid #e4e7ed;
  position: absolute;
  top: 40px;
  left: 0px;
  padding: 5px 8px;
  z-index: 10;
}

.cus_tabs {
  margin-bottom: 8px;
  .cus_tabs_title {
    font-weight: 600;
    margin-bottom: 4px;
  }
  .cus_tabs_body {
    margin-left: 12px;
  }
}

.custom-tag {
  color: #909399;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  line-height: 1;
  border-radius: 4px;
  white-space: nowrap;
  font-size: 13px;
  margin-right: 5px;
  background-color: #f0f2f5;
}

.custom_mask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
2、使用api介紹

1、樹(shù)形結(jié)構(gòu)入?yún)ⅲ?code>dataSource=[{ ext: "服務(wù)器狀態(tài)", children: [{ text: "在線", value: 0}]}],
2、標(biāo)簽引用:<ivuSelect :maxLength="2" ref="ivuSelectRef" v-model="customSelect" :dataSource="deviceDataList" style="width: 100%; margin-left: 5px" />
3、相關(guān)api說(shuō)明文檔在文章底部文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-638000.html

參數(shù) 說(shuō)明 類型 默認(rèn)值 必填項(xiàng)
dataSource [{}]-label,value;樹(shù)形結(jié)構(gòu) Array[] []
modelValue 當(dāng)前選中項(xiàng)內(nèi)容 Array []
placeholder 輸入框內(nèi)容 String 請(qǐng)輸入
multiple 是否開(kāi)啟多選 Boolean false
maxLength 輸入框最大標(biāo)簽長(zhǎng)度 Number 3

到了這里,關(guān)于uni-app微信小程序開(kāi)發(fā)自定義select下拉多選內(nèi)容篇的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • uni-app+vue3+vite+微信小程序開(kāi)發(fā)的問(wèn)題點(diǎn)

    目錄名稱不能為api,否則會(huì)出現(xiàn) ├F10: PM┤ [vite] getaddrinfo ENOTFOUND rivtrust.jz-xxx.xyz ,修改為_(kāi)api; vue3的全局變量掛載 或者 全局變量的引入: 或者 axios在微信小程序上使用的問(wèn)題: 安裝模塊 出現(xiàn)adapter is not a function的解決方法 需要axios自定義適配器配置 整體代碼request.js: un

    2024年02月13日
    瀏覽(48)
  • Uni-App 中使用微信小程序開(kāi)發(fā),你可以通過(guò)以下步驟來(lái)設(shè)置節(jié)點(diǎn)屬性

    在 Uni-App 中使用微信小程序開(kāi)發(fā),你可以通過(guò)以下步驟來(lái)設(shè)置節(jié)點(diǎn)屬性: 在模板中定義節(jié)點(diǎn):在 wxml 文件中,使用標(biāo)簽定義要操作的節(jié)點(diǎn),并為它添加一個(gè)唯一的 id 屬性,例如: ? 在 js 文件中獲取節(jié)點(diǎn)的引用:使用? uni.createSelectorQuery() ?方法創(chuàng)建選擇器查詢對(duì)象,并使用

    2024年02月15日
    瀏覽(22)
  • uni-app啟動(dòng)小程序篇(字節(jié),微信)

    uni-app啟動(dòng)小程序篇(字節(jié),微信)

    uni-app啟動(dòng)小程序篇 uni-app在字節(jié)工具小程序啟動(dòng) 1.1 在Hbuild X點(diǎn)擊運(yùn)行, 進(jìn)入運(yùn)行設(shè)置 1.2 進(jìn)入運(yùn)行設(shè)置后,設(shè)置字節(jié)小程序的運(yùn)行位置 ? 1.3 以上配置完成后,點(diǎn)擊運(yùn)行到小程序 ? 1.4 啟動(dòng)成功后 復(fù)制該地址 ? 1.5 打開(kāi)字節(jié)小程序,選小程序,點(diǎn)擊新建 ? 1.6 進(jìn)入后點(diǎn)擊導(dǎo)入項(xiàng)目,將剛

    2024年02月11日
    瀏覽(24)
  • uni-app 微信小程序端-AirKiss一鍵配網(wǎng)

    uni-app 微信小程序端-AirKiss一鍵配網(wǎng)

    發(fā)現(xiàn)網(wǎng)上很多關(guān)于微信小程序配網(wǎng)的文章都是微信小程序原生開(kāi)發(fā),uni-app少之又少。這篇文章就介紹一下怎么在HBuilder X使用airkiss配網(wǎng)插件。 一.AirKiss介紹 ? AirKiss是微信硬件平臺(tái)為Wi-Fi設(shè)備提供的微信配網(wǎng)、局域網(wǎng)發(fā)現(xiàn)和局域網(wǎng)通訊的技術(shù)。開(kāi)發(fā)者若要實(shí)現(xiàn)通過(guò)微信客戶端

    2024年02月08日
    瀏覽(20)
  • uni-app +java小程序端對(duì)接微信登陸

    uni-app +java小程序端對(duì)接微信登陸

    要想實(shí)現(xiàn)微信登陸,首先必須注冊(cè)開(kāi)發(fā)者賬號(hào)。 登錄微信開(kāi)放平臺(tái),添加移動(dòng)應(yīng)用并提交審核,審核通過(guò)后可獲取應(yīng)用ID(AppID),AppSecret等信息 在應(yīng)用詳情中 申請(qǐng)開(kāi)通 微信登錄功能,根據(jù)頁(yè)面提示填寫(xiě)資料,提交審核 申請(qǐng)審核通過(guò)后即可打包使用微信授權(quán)登錄功能 1.app端

    2024年02月11日
    瀏覽(28)
  • uni-app 支持 app端, h5端,微信小程序端 圖片轉(zhuǎn)換文件格式 和 base64

    uni-app 支持 app端 h5端,微信小程序端 圖片轉(zhuǎn)換文件格式 和 base64,下方是插件市場(chǎng)的地址 app端 h5端,微信小程序端 圖片轉(zhuǎn)換文件格式 和 base64 - DCloud 插件市場(chǎng) https://ext.dcloud.net.cn/plugin?id=13926

    2024年02月13日
    瀏覽(91)
  • uni-app 微信小程序端調(diào)用掃一掃識(shí)別小程序碼(菊花碼,太陽(yáng)碼)
  • uni-app移動(dòng)端-H5-微信小程序下載保存圖片,文檔和視頻到手機(jī),帶進(jìn)度條

    可移步插件地址,可直接導(dǎo)入hbuilderx示例項(xiàng)目查看: uni-app移動(dòng)端-H5-微信小程序下載保存圖片,文檔和視頻到手機(jī),帶進(jìn)度條 具體代碼如下

    2024年02月13日
    瀏覽(27)
  • uni-app 微信小程序自定義導(dǎo)航欄

    uni-app 微信小程序自定義導(dǎo)航欄

    上面的導(dǎo)航欄主要由狀態(tài)欄(就是手機(jī)電量顯示欄)和小程序的導(dǎo)航欄組成,android手機(jī)一般為48px,ios手機(jī)一般為44px 1、設(shè)置navigationStyle:custom 2、頁(yè)面導(dǎo)航欄div 3、獲取statusBarHeight高度 4、獲取navTitleHeight的高度

    2024年02月14日
    瀏覽(95)
  • uni-app微信小程序,APP都適用自定義頂部導(dǎo)航

    uni-app微信小程序,APP都適用自定義頂部導(dǎo)航

    *使用自定義的導(dǎo)航樣式,首先需要把原生的頂部的導(dǎo)航方式給隱藏掉(\\\"navigationStyle\\\": \\\"custom\\\") *手機(jī)頂部手機(jī)狀態(tài)欄的高度 *微信小程序中膠囊的位置信息存儲(chǔ)(使用store存儲(chǔ)) *由于微信小程序中帶有導(dǎo)航膠囊,所以需要根據(jù)膠囊去獲取一定的參數(shù)信息 在微信小程序中,我們只需要獲

    2024年02月06日
    瀏覽(91)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包