{"id":15626734,"url":"https://github.com/shuirong/vue-drag-tree","last_synced_at":"2025-04-12T19:45:20.285Z","repository":{"id":21907748,"uuid":"94400440","full_name":"shuiRong/vue-drag-tree","owner":"shuiRong","description":"🌴🌳a Vue's drag and drop tree component || 🌾Demo ","archived":false,"fork":false,"pushed_at":"2022-09-07T13:56:33.000Z","size":3592,"stargazers_count":388,"open_issues_count":9,"forks_count":93,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-03T23:09:06.016Z","etag":null,"topics":["drag","drop","npm-package","tree","vue","vue-components","vue-drag-tree"],"latest_commit_sha":null,"homepage":"https://vigilant-curran-d6fec6.netlify.com/#/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shuiRong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-15T04:42:36.000Z","updated_at":"2025-03-26T14:51:51.000Z","dependencies_parsed_at":"2023-01-12T03:46:09.252Z","dependency_job_id":null,"html_url":"https://github.com/shuiRong/vue-drag-tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuiRong%2Fvue-drag-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuiRong%2Fvue-drag-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuiRong%2Fvue-drag-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuiRong%2Fvue-drag-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuiRong","download_url":"https://codeload.github.com/shuiRong/vue-drag-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625491,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drag","drop","npm-package","tree","vue","vue-components","vue-drag-tree"],"created_at":"2024-10-03T10:13:34.022Z","updated_at":"2025-04-12T19:45:20.267Z","avatar_url":"https://github.com/shuiRong.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-drag-tree\n\n[![Version](http://img.shields.io/npm/v/vue-drag-tree.svg)](https://www.npmjs.com/package/vue-drag-tree)[![Downloads](http://img.shields.io/npm/dm/vue-drag-tree.svg)](https://www.npmjs.com/package/vue-drag-tree)[![License](https://img.shields.io/npm/l/vue-drag-tree.svg?style=flat)](https://opensource.org/licenses/MIT)\n\n\u003e It's a tree components(Vue2.x) that allow you to drag and drop the node to exchange their data .\n\n**Feature**\n\n- **Double click** on an node to turn it into a folder\n- **Drag and Drop** the tree node, even between two different levels\n- **Customize your node (how to display node. eg: node name and left icon )**\n- **Controls** whether a particular node can **be dragged** and whether the node can be plugged into other nodes\n- **Append/Remove** Node in any level (#TODO)\n\n**[中文](README_ZH.md)** || **Please Star! if it's helpful**.\n**[Example Project](https://github.com/shuiRong/vue-drag-tree-demo)**\n\n### Preview\n\n---\n\n![demo](static/preview.gif)\n\n### Getting Start\n\n---\n\n**Install**\n\n`npm install vue-drag-tree --S`\n\nor\n\n`yarn add vue-drag-tree -S`\n\n**Usage**\n\nthe following code is come from [here](https://github.com/shuiRong/vue-drag-tree-demo)\n\n\n\n**P.S.** If you get error about` Vue packages version mismatch`\n\n\n```bash\n// Update the version of Vue and vue-template-compiler to latest is fine.  \nnpm install vue@latest -S\nnpm install vue-template-compiler@latest -D\n```\n\nmain.js\n\n```vue\nimport Vue from 'vue'\nimport VueDragTree from 'vue-drag-tree'\nimport 'vue-drag-tree/dist/vue-drag-tree.min.css'\n\nVue.use(VueDragTree)\n```\n\ntest.vue\n\n```vue\n\u003ctemplate\u003e\n\t\u003cvue-drag-tree :data='data' :allowDrag='allowDrag' :allowDrop='allowDrop' :defaultText='\"New Node\"' @current-node-clicked='curNodeClicked' @drag=\"dragHandler\" @drag-enter=\"dragEnterHandler\" @drag-leave=\"dragLeaveHandler\" @drag-over=\"dragOverHandler\" @drag-end=\"dragEndHandler\" @drop=\"dropHandler\" v-slot=\"slotProps\"\u003e\n    \u003c!-- customize your node here if don't like the default / 如果你不喜欢默认样式，可以在这里定制你自己的节点 --\u003e\n    \u003cspan :class=\"[slotProps.isClicked ? 'i-am-clicked' : 'i-am-not-clicked']\"\u003e\u003c/span\u003e\n    \u003cspan class='i-am-node-name'\u003e{{slotProps.nodeName}}\u003c/span\u003e\n    \u003c/vue-drag-tree\u003e\n\u003c/template\u003e\n\u003cscript\u003e\nexport default{\n  data(){\n    return{\n      data: [\n        {\n          name: 'Node 0-0',\n          id: 0,\n          children: [\n            {\n              name: 'Node 1-1',\n              id: 3,\n              children: [\n                {\n                  name: 'Node 2-1',\n                  id: 4,\n                  children: []\n                },\n                {\n                  name: 'Node 2-2',\n                  id: 10,\n                  children: []\n                }\n              ]\n            },\n            {\n              name: 'Node 1-2',\n              id: 13,\n              children: []\n            }\n          ]\n        },\n        {\n          name: 'Node 0-1',\n          id: 14,\n          children: []\n        }\n      ]\n    }\n  },\n  methods: {\n   \tallowDrag(model, component) {\n      if (model.name === 'Node 0-1') {\n        // can't be dragged\n        return false;\n      }\n      // can be dragged\n      return true;\n    },\n    allowDrop(model, component) {\n      if (model.name === 'Node 2-2') {\n        // can't be placed\n        return false;\n      }\n      // can be placed\n      return true;\n    },\n    curNodeClicked(model, component) {\n      // console.log('curNodeClicked', model, component);\n    },\n    dragHandler(model, component, e) {\n      // console.log('dragHandler: ', model, component, e);\n    },\n    dragEnterHandler(model, component, e) {\n      // console.log('dragEnterHandler: ', model, component, e);\n    },\n    dragLeaveHandler(model, component, e) {\n      // console.log('dragLeaveHandler: ', model, component, e);\n    },\n    dragOverHandler(model, component, e) {\n      // console.log('dragOverHandler: ', model, component, e);\n    },\n    dragEndHandler(model, component, e) {\n      // console.log('dragEndHandler: ', model, component, e);\n    },\n    dropHandler(model, component, e) {\n      // console.log('dropHandler: ', model, component, e);\n    }\n  }\n}\n\u003cscript\u003e\n```\n\n### API\n\n---\n\n**Attributes**\n\n| Name           | Description                                          | Type     | Default    |\n| :------------- | :--------------------------------------------------- | :------- | :--------- |\n| data           | data of the tree                                     | Array    | －－       |\n| defaultText    | default text of new node                             | String   | \"New Node\" |\n| allowDrag      | Judging which node can be dragged                    | Function | ()=\u003etrue   |\n| allowDrop      | Judging which node can be plugged into other nodes   | Function | ()=\u003etrue   |\n| disableDBClick | disable append a new child node by double click node | Boolean  | false      |\n\n\n\n**Method**\n\n| Name                 | Description                                                                                      | arguments                                                                                                          |\n| -------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |\n| current-node-clicked | Tell you which node was clicked                                                                  | (model,component) model:  node data was clicked． component: VNode data for the node was clicked                   |\n| drag                 | The `drag` event is fired every few hundred milliseconds as an node is being dragged by the user | (model,component,e) model: node data was dragged. component: VNode data for the node was dragged; e: drag event    |\n| drag-enter           | The `drag-enter` event is fired when a dragged node enters a valid drop target                   | (model,component,e) model: data of the valid drop target; component: VNode of the valid drop target; e: drag event |\n| drag-leave           | The `drag-leave` event is fired when a dragged node leaves a valid drop target                   | (model,component,e) model: data of the valid drop target; component: VNode of the valid drop target; e: drag event |\n| drag-over            | The `drag-over` event is fired when an node is being dragged over a valid drop target            | (model,component,e) model: data of the valid drop target; component: VNode of the valid drop target; e: drag event |\n| drag-end             | The `drag-end` event is fired when a drag operation is being ended                               | (model,component,e) model: node data was dragged. component: VNode data for the node was dragged; e: drag event    |\n| drop                 | The **drop** event is fired when an node is dropped on a valid drop target.                      | (model,component,e) model: data of the valid drop target; component: VNode of the valid drop target; e: drag event |\n\n**Slot**\n\n```vue\n\u003cvue-drag-tree ... v-slot=\"slotProps\"\u003e\n    \u003c!-- customize your node here if don't like the default --\u003e\n    \u003cspan :class=\"[slotProps.isClicked ? 'i-am-clicked' : 'i-am-not-clicked']\"\u003e\u003c/span\u003e\n    \u003cspan class='i-am-node-name'\u003e{{slotProps.nodeName}}\u003c/span\u003e\n\u003c/vue-drag-tree\u003e\n```\n\n`slotProps`has two attributes：\n\n| attribute name | description                                  | value type |\n| -------------- | -------------------------------------------- | ---------- |\n| nodeName       | the name of displaying node                  | String     |\n| isClicked      | if the node is clicked (true means expanded) | Boolean    |\n\n\n\n**License**\n\n---\n\n[The 996ICU License (996ICU)](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuirong%2Fvue-drag-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuirong%2Fvue-drag-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuirong%2Fvue-drag-tree/lists"}