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

Vue3+elementPlus中 樹形控件封裝的實(shí)現(xiàn)

 更新時(shí)間:2025年04月15日 08:30:28   作者:知否灬知否  
本文主要介紹了Vue3+elementPlus中 樹形控件封裝的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1.組件

<template>
  <div class="selection">
    <el-select placeholder="請選擇" v-model="nameList" clearable @clear="handleClear" ref="selectUpResId" style="width: 100%">
      <el-option hidden :key="1" :value="1"></el-option
      ><!--這個(gè)必不可少否則顯示不出來下拉數(shù)據(jù)-->
      <!-- check-strictly :父子是否聯(lián)動(dòng),根據(jù)業(yè)務(wù)修改 -->
      <el-tree
        :data="options"
        node-key="id"
        :props="defaultProps"
        :default-checked-keys="huixianarr"
        @check="handleNodeClick"
        show-checkbox
        ref="treeRef"
        :check-strictly="true"
      >
      </el-tree>
    </el-select>
  </div>
</template>
<script setup name="selects">
import { ref, reactive } from "vue";
//接受父組件傳來的數(shù)據(jù)
const props = defineProps({
  treeFilterData: {
    type: Array,
    default: () => [] //樹形控件數(shù)據(jù)源
  },
  treeHxlist: {
    type: Array,
    default: () => [] //回顯ID集合,根據(jù)業(yè)務(wù)修改
  },
  dfProps: {
    type: Object,
    default: () => {} //樹形控件配置項(xiàng),根據(jù)業(yè)務(wù)修改
  }
});
const treeRef = ref();
let nameList = ref("");
let huixianarr = ref([]);
let idList = ref();
let options = ref([]);
let defaultProps = ref({});
defaultProps.value = props.dfProps;
let hxlist = ref([]);
let treeForm = ref();
let list = ref();
var propertyName = props.dfProps.label;
init();
function init() {
  options.value = props.treeFilterData;
  huixianarr.value = props.treeHxlist;
  let hxlist = findPathsByIds(options.value, huixianarr.value);
  nameList.value = hxlist.join(","); //顯示內(nèi)容
}
const emit = defineEmits(["checKedId"]);
function handleNodeClick(data, lst) {
  let arr = [],
    name = [];
  lst.checkedNodes.forEach(item => {
    //過濾拿到選中的id
    arr.push(item.id);
  });
  lst.checkedNodes.forEach(item => {
    //過濾拿到選中的name

    name.push(item[propertyName]);
  });
  nameList.value = name.join(","); //顯示內(nèi)容
  idList.value = arr; //后臺(tái)傳參需要的id
  //傳給父組件

  emit("checKedId", idList.value);
}
function handleClear() {
  hxlist.value = [];
  idList.value = []; //id集合
  nameList.value = ""; //input顯示內(nèi)容
  huixianarr.value = []; //回顯ID集合
  treeRef.value.setCheckedKeys([]); //清空
}
function findPathsByIds(data, targetIds) {
  const resultPaths = []; // 存儲(chǔ)匹配的 title

  // 輔助函數(shù):遞歸查找單個(gè) id 的 title
  function findPathRecursive(items, targetId) {
    for (const item of items) {
      // 如果當(dāng)前項(xiàng)的 id 匹配,添加其 title 到結(jié)果數(shù)組
      if (item.id === targetId) {
        resultPaths.push(item[propertyName]);
        return; // 找到后直接返回
      }

      // 如果有 children,遞歸查找
      if (item.children && item.children.length > 0) {
        findPathRecursive(item.children, targetId);
      }
    }
  }

  // 遍歷目標(biāo) id 數(shù)組,逐一查找
  for (const id of targetIds) {
    findPathRecursive(data, id);
  }
  return resultPaths;
}
</script>
<style scoped>
.selection {
  width: 300px;
}
</style>



2.使用

 <Selectoption :treeFilterData="treeFilterData" :treeHxlist="treeHxlist" :dfProps="dfProps" @checKedId="gettreelist" />
//回顯
const treeFilterData = ref([1]); 
//格式
let dfProps = ref({
  children: "children",
  label: "title"
});  
//數(shù)據(jù)
const treeFilterData = ref([
    {
      "id": 1,
      "path": "/home/index",
      "name": "home",
      "component": "/home/index",
      "title": "首頁",
      "meta": {
        "icon": "HomeFilled",
        "title": "首頁",
        "isLink": "",
        "isHide": false,
        "isFull": false,
        "isAffix": true,
        "isKeepAlive": true
      }
    },
    {
      "id": 6,
      "path": "/system",
      "name": "system",
      "redirect": "/system/accountManage",
      "title": "系統(tǒng)管理",
      "meta": {
        "icon": "Tools",
        "title": "系統(tǒng)管理",
        "isLink": "",
        "isHide": false,
        "isFull": false,
        "isAffix": false,
        "isKeepAlive": true
      },
      "children": [
        {
          "id": 61,
          "father": 6,
          "path": "/system/accountManage",
          "name": "accountManage",
          "component": "/system/accountManage/index",

          "title": "賬號管理",
          "meta": {
            "icon": "Menu",
            "title": "賬號管理",
            "isLink": "",
            "isHide": false,
            "isFull": false,
            "isAffix": false,
            "isKeepAlive": true
          }
        },
        
        
      ]
    }
  ]);

到此這篇關(guān)于Vue3+elementPlus中 樹形控件封裝的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Vue3 elementPlus樹形控件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Vite多環(huán)境配置及變量識(shí)別規(guī)則

    Vite多環(huán)境配置及變量識(shí)別規(guī)則

    這篇文章主要為大家介紹了Vite多環(huán)境配置時(shí)間及vite識(shí)別環(huán)境變量的規(guī)則,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Vue生命周期與后端交互實(shí)現(xiàn)流程詳解

    Vue生命周期與后端交互實(shí)現(xiàn)流程詳解

    Vue的生命周期就是vue實(shí)例從創(chuàng)建到銷毀的全過程,也就是new Vue()開始就是vue生命周期的開始。Vue實(shí)例有?個(gè)完整的?命周期,也就是從開始創(chuàng)建、初始化數(shù)據(jù)、編譯模版、掛載Dom->渲染、更新->渲染、卸載等?系列過程,稱這是Vue的?命周期
    2022-11-11
  • vue3中引入class類的寫法代碼示例

    vue3中引入class類的寫法代碼示例

    最近一直在做vue項(xiàng)目,從網(wǎng)上搜索到的資料不太多,這篇文章主要給大家介紹了關(guān)于vue3中引入class類的寫法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • Vue?github用戶搜索案例分享

    Vue?github用戶搜索案例分享

    這篇文章主要介紹了Vue?github用戶搜索案例分享,文章基于Vue的相關(guān)資料展開對主題的詳細(xì)介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-04-04
  • Pinia介紹及工作原理解析

    Pinia介紹及工作原理解析

    這篇文章主要為大家介紹了Pinia介紹及工作原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • vue使用路由的query配置項(xiàng)時(shí)清除地址欄的參數(shù)案例詳解

    vue使用路由的query配置項(xiàng)時(shí)清除地址欄的參數(shù)案例詳解

    這篇文章主要介紹了vue使用路由的query配置項(xiàng)時(shí)如何清除地址欄的參數(shù),本文通過案例給大家分享完美解決方案,需要的朋友可以參考下
    2023-09-09
  • Vue js如何用split切分并去掉空值和item的空格

    Vue js如何用split切分并去掉空值和item的空格

    這篇文章主要介紹了Vue js如何用split切分并去掉空值和item的空格,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • JavaScript獲取echart曲線上任意點(diǎn)位的值詳解

    JavaScript獲取echart曲線上任意點(diǎn)位的值詳解

    這篇文章主要為大家介紹了JavaScript獲取echart曲線上任意點(diǎn)位的值詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vue中的Vux配置指南

    Vue中的Vux配置指南

    Vux是Vue.js的一個(gè)ui庫,官網(wǎng)在這里,官方文檔的配置指南側(cè)重于技術(shù)的羅列,我這里簡化一下Vux的配置流程。感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧
    2017-12-12
  • Vue實(shí)現(xiàn)數(shù)字動(dòng)畫的幾種方案

    Vue實(shí)現(xiàn)數(shù)字動(dòng)畫的幾種方案

    本文介紹了三種使用Vue實(shí)現(xiàn)動(dòng)態(tài)數(shù)字動(dòng)畫的方案:使用Vue的響應(yīng)式數(shù)據(jù)與`setInterval`逐步更新數(shù)字,通過Vue的動(dòng)畫API和CSS動(dòng)畫效果為數(shù)字增加過渡效果,以及使用更高效的`requestAnimationFrame`來提供更加流暢的動(dòng)畫表現(xiàn),每種方案都詳細(xì)說明了原理、實(shí)現(xiàn)步驟和代碼示例
    2025-02-02

最新評論

霍林郭勒市| 德州市| 陆河县| 横峰县| 通江县| 甘肃省| 富川| 建德市| 上思县| 宽城| 铜鼓县| 革吉县| 中超| 巫山县| 琼海市| 东乡| 福安市| 赣榆县| 凤凰县| 息烽县| 肇庆市| 阿勒泰市| 墨竹工卡县| 崇明县| 万荣县| 开封县| 晋中市| 小金县| 安庆市| 黄骅市| 买车| 西吉县| 博野县| 麻栗坡县| 清远市| 政和县| 永丰县| 九台市| 长兴县| 辽宁省| 忻城县|