亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue elementui tree 任意級(jí)別拖拽功能代碼

 更新時(shí)間:2020年08月31日 10:14:26   作者:心向陽(yáng)光,便是晴天  
這篇文章主要介紹了vue elementui tree 任意級(jí)別拖拽功能代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

我的是根據(jù)父級(jí)id做的一些判斷

<el-tree
     draggable :allow-drop="allowDrop" @node-drop="sort"
     accordion style="font-size:14px;width:250px;"
     ref="tree" :data="catalogList" :props="defaultProps" :expand-on-click-node="false"
     node-key="id" :highlight-current="true" :load="loadNode"
     lazy :render-content="renderContent" @node-click="handleNodeClick"
     empty-text="暫無(wú)數(shù)據(jù)">
 
   allowDrop(draggingNode, dropNode, type){
   //注掉的是同級(jí)拖拽
   /* if (draggingNode.data.level === dropNode.data.level) {
    if (draggingNode.data.aboveId === dropNode.data.aboveId) {
     return type === 'prev' || type === 'next'
    }
   } else {
    // 不同級(jí)進(jìn)行處理
    return false
   } */
   //任意級(jí)別拖拽
   if (draggingNode.data.aboveId === dropNode.data.aboveId) {
     return type === 'prev' || type === 'next'
   } else {
    return type === 'prev' || type === 'next' || type === 'inner'
   }
  },
  //拖拽完成之后要重新排序
  /* 
  * draggingNode:被拖拽節(jié)點(diǎn)對(duì)應(yīng)的 Node
  * dropNode:結(jié)束拖拽時(shí)最后進(jìn)入的節(jié)點(diǎn)
  * type: 被拖拽節(jié)點(diǎn)的放置位置(before、after、inner)
  * event
  */
  sort(draggingNode,dropNode,type,event) {
   console.log(draggingNode)
   console.log(dropNode)
   if (draggingNode.data.aboveId === dropNode.data.aboveId) {
    let obj = {
     aboveId:'',
     arr:[]
    }
    obj.aboveId = dropNode.data.aboveId
    for (let item of dropNode.parent.childNodes) {
     obj.arr.push(item.data.id)
    }
    console.log(obj)
    this.updateOrderMe(obj)
   } else {
    let obj = {
     aboveId:'',
     id:'',
     newAboveId:''
    }
    obj.aboveId = draggingNode.data.aboveId
    obj.id = draggingNode.data.id
    obj.newAboveId = dropNode.data.id
    this.randomDrag(obj)
   }
  },
  randomDrag(obj) {
   this.$http
    .post(url, obj).then(res =>{
	    if (!res.data.success) {
	     this.$message.warning(res.data.msg)
	    }
    })
  },
  updateOrderMe(obj) {
   this.$http
    .post(url, {
     aboveId:obj.aboveId,
     ids: obj.arr
    }).then(res =>{
	    if (!res.data.success) {
	     this.$message.warning(res.data.msg)
	    }
    })
  }

補(bǔ)充知識(shí):element-ui tree 實(shí)現(xiàn)同級(jí)拖拽

我就廢話不多說(shuō)了,大家還是直接看代碼吧~

<template>
 <div>
  <el-tree
   draggable
   :allow-drop="allowDrop"
   @node-drop="sort"
   ref="tree"
   :data="data2"
   :props="defaultProps"
   show-checkbox
   default-expand-all
   node-key="id"
   highlight-current
  ></el-tree>
 
  <div class="buttons">
   <el-button @click="getCheckedNodes">通過(guò) node 獲取</el-button>
   <el-button @click="getCheckedKeys">通過(guò) key 獲取</el-button>
   <el-button @click="setCheckedNodes">通過(guò) node 設(shè)置</el-button>
   <el-button @click="setCheckedKeys">通過(guò) key 設(shè)置</el-button>
   <el-button @click="resetChecked">清空</el-button>
  </div>
 </div>
</template>
 
<script>
// import draggable from "vuedraggable";
// import Sortable from "sortablejs";
export default {
 methods: {
  getCheckedNodes() {
   console.log(this.$refs.tree.getCheckedNodes());
  },
  getCheckedKeys() {
   console.log(this.$refs.tree.getCheckedKeys());
  },
  setCheckedNodes() {
   this.$refs.tree.setCheckedNodes([
    {
     id: 5,
     label: "二級(jí) 2-1"
    },
    {
     id: 9,
     label: "三級(jí) 1-1-1"
    }
   ]);
  },
  setCheckedKeys() {
   this.$refs.tree.setCheckedKeys([3]);
  },
  resetChecked() {
   this.$refs.tree.setCheckedKeys([]);
  }
 },
 mounted() {
  const el = document.querySelectorAll(".el-tree")[0];
  console.log(el);
 },
 data() {
  return {
   data2: [
    {
     id: 1,
     label: "一級(jí) 1",
     children: [
      {
       id: 4,
       label: "二級(jí) 1-1",
       prop: "4"
      }
     ]
    },
    {
     id: 2,
     label: "一級(jí) 2",
     children: [
      {
       id: 5,
       label: "二級(jí) 2-1",
       prop: "5"
      },
      {
       id: 6,
       label: "二級(jí) 2-2",
       prop: "6"
      }
     ]
    },
    {
     id: 3,
     label: "一級(jí) 3",
     children: [
      {
       id: 7,
       label: "二級(jí) 3-1",
       prop: "7"
      },
      {
       id: 8,
       label: "二級(jí) 3-2",
       prop: "9"
      }
     ]
    },
    {
     id: 9,
     label: "一級(jí)4"
    }
   ],
   defaultProps: {
    children: "children",
    label: "label"
   },
   allowDrop(draggingNode, dropNode, type) {
    if (draggingNode.level === dropNode.level) {
     if (draggingNode.parent.id === dropNode.parent.id) {
      // 向上拖拽 || 向下拖拽
      return type === "prev" || type === "next";
     }
    } else {
     // 不同級(jí)進(jìn)行處理
     return false;
    }
   },
   sort(draggingNode, dropNode, type, event) {
    // console.log('排序')
    // console.log("<><><>>><><<><><><><><><><>")
    // 拖拽之后的重新組合的數(shù)組
    // console.log(dropNode.parent); //dropNode.parent.childNodes =[]
    let obj = {
     aboveId: "",
     arr: []
    };
    obj.aboveId = dropNode.data.aboveId;
    for (let item of dropNode.parent.childNodes) {
     obj.arr.push(item.data.id);
    }
   }
  };
 }
};
</script>

以上這篇vue elementui tree 任意級(jí)別拖拽功能代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3父子組件相互調(diào)用方法舉例詳解

    Vue3父子組件相互調(diào)用方法舉例詳解

    這篇文章主要給大家介紹了關(guān)于Vue3父子組件相互調(diào)用方法的相關(guān)資料,vue中我們常常用到組件,那么組件中互相調(diào)用也是經(jīng)常遇到的,需要的朋友可以參考下
    2023-08-08
  • 解決Vue_localStorage本地存儲(chǔ)和本地取值問(wèn)題

    解決Vue_localStorage本地存儲(chǔ)和本地取值問(wèn)題

    這篇文章主要介紹了解決Vue_localStorage本地存儲(chǔ)和本地取值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Vue 框架之鍵盤(pán)事件、健值修飾符、雙向數(shù)據(jù)綁定

    Vue 框架之鍵盤(pán)事件、健值修飾符、雙向數(shù)據(jù)綁定

    這篇文章主要介紹了Vue 框架之鍵盤(pán)事件、健值修飾符、雙向數(shù)據(jù)綁定問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-11-11
  • vue實(shí)現(xiàn)聊天框發(fā)送表情

    vue實(shí)現(xiàn)聊天框發(fā)送表情

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)聊天框發(fā)送表情,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue實(shí)現(xiàn)文件切片上傳功能的示例代碼

    Vue實(shí)現(xiàn)文件切片上傳功能的示例代碼

    在實(shí)際開(kāi)發(fā)項(xiàng)目過(guò)程中有時(shí)候需要上傳比較大的文件,然后呢,上傳的時(shí)候相對(duì)來(lái)說(shuō)就會(huì)慢一些,so,后臺(tái)可能會(huì)要求前端進(jìn)行文件切片上傳。本文介紹了Vue實(shí)現(xiàn)文件切片上傳的示例代碼,需要的可以參考一下
    2022-10-10
  • 詳解mpvue小程序中怎么引入iconfont字體圖標(biāo)

    詳解mpvue小程序中怎么引入iconfont字體圖標(biāo)

    這篇文章主要介紹了詳解mpvue小程序中怎么引入iconfont字體圖標(biāo),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10
  • Vue3+ElementUI 多選框中復(fù)選框和名字點(diǎn)擊方法效果分離方法

    Vue3+ElementUI 多選框中復(fù)選框和名字點(diǎn)擊方法效果分離方法

    這篇文章主要介紹了Vue3+ElementUI 多選框中復(fù)選框和名字點(diǎn)擊方法效果分離方法,文中補(bǔ)充介紹了VUE-Element組件 CheckBox多選框使用方法,需要的朋友可以參考下
    2024-01-01
  • el-table 行合并的實(shí)現(xiàn)示例

    el-table 行合并的實(shí)現(xiàn)示例

    本文主要介紹了el-table 行合并的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue-extend和vue-component注冊(cè)一個(gè)全局組件方式

    vue-extend和vue-component注冊(cè)一個(gè)全局組件方式

    這篇文章主要介紹了vue-extend和vue-component注冊(cè)一個(gè)全局組件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • 在Vue3中實(shí)現(xiàn)懶加載功能的代碼示例

    在Vue3中實(shí)現(xiàn)懶加載功能的代碼示例

    在現(xiàn)代前端開(kāi)發(fā)中,懶加載是一種提高應(yīng)用性能和用戶體驗(yàn)的重要技術(shù),尤其是在處理較大圖片或長(zhǎng)列表數(shù)據(jù)時(shí),本文將使用 Vue 3 和其新推出的 setup 語(yǔ)法糖來(lái)實(shí)現(xiàn)懶加載功能,并提供具體的示例代碼,需要的朋友可以參考下
    2024-09-09

最新評(píng)論