欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue elementui tree 任意級別拖拽功能代碼

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

我的是根據(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="暫無數(shù)據(jù)">
 
   allowDrop(draggingNode, dropNode, type){
   //注掉的是同級拖拽
   /* if (draggingNode.data.level === dropNode.data.level) {
    if (draggingNode.data.aboveId === dropNode.data.aboveId) {
     return type === 'prev' || type === 'next'
    }
   } else {
    // 不同級進(jìn)行處理
    return false
   } */
   //任意級別拖拽
   if (draggingNode.data.aboveId === dropNode.data.aboveId) {
     return type === 'prev' || type === 'next'
   } else {
    return type === 'prev' || type === 'next' || type === 'inner'
   }
  },
  //拖拽完成之后要重新排序
  /* 
  * draggingNode:被拖拽節(jié)點對應(yīng)的 Node
  * dropNode:結(jié)束拖拽時最后進(jìn)入的節(jié)點
  * type: 被拖拽節(jié)點的放置位置(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)
	    }
    })
  }

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

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

<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">通過 node 獲取</el-button>
   <el-button @click="getCheckedKeys">通過 key 獲取</el-button>
   <el-button @click="setCheckedNodes">通過 node 設(shè)置</el-button>
   <el-button @click="setCheckedKeys">通過 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: "二級 2-1"
    },
    {
     id: 9,
     label: "三級 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: "一級 1",
     children: [
      {
       id: 4,
       label: "二級 1-1",
       prop: "4"
      }
     ]
    },
    {
     id: 2,
     label: "一級 2",
     children: [
      {
       id: 5,
       label: "二級 2-1",
       prop: "5"
      },
      {
       id: 6,
       label: "二級 2-2",
       prop: "6"
      }
     ]
    },
    {
     id: 3,
     label: "一級 3",
     children: [
      {
       id: 7,
       label: "二級 3-1",
       prop: "7"
      },
      {
       id: 8,
       label: "二級 3-2",
       prop: "9"
      }
     ]
    },
    {
     id: 9,
     label: "一級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ì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 任意級別拖拽功能代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(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本地存儲和本地取值問題

    解決Vue_localStorage本地存儲和本地取值問題

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

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

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

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

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

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

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

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

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

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

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

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

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

    vue-extend和vue-component注冊一個全局組件方式

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

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

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

最新評論