New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

draggable-vue-directive

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draggable-vue-directive

A simple directive to handle drag and drop of any Vue component

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
decreased by-14.86%
Maintainers
1
Weekly downloads
 
Created
Source

draggable-vue-directive

GitHub open issues npm download npm download per month npm version Package Quality vue2 MIT License

Vue directive (Vue.js 2.0) for handling element drag & drop.

Getting Started

npm install draggable-vue-directive --save

Demo

demo gif

Typical use:

<div v-draggable>
    classic draggable
</div>

.vue file:

  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
  ...

with handler:

<div v-draggable="draggableValue">
    <div :ref="handleId">
        <img src="../assets/move.svg" alt="move">
    </div>
    drag and drop using handler
</div>

.vue file:

  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
        data() {
            return {
                handleId: "handle-id",
                draggableValue: { };
            }
        },
        mounted() {
            this.draggableValue.handle = this.$refs[this.handleId];
        }
  ...

draggable value

handle

Type: HtmlElement | Vue
Required: false

There are two ways to use the draggable-vue-directive as showen in the demo above.
The simple use is just to put the directive on any Vue component or Html element and boom! the element is draggable.
The second option is to use handler. if you choose to use handler, the component itself will be draggable only using the handler.

onPositionChange

Type: Function
Required: false

In some cases it is useful to know the coordinates of the element when it's been dragged.
Passing a callback to draggableValue will achieve this goal and every time the element is being dragged the callback will be executed with the current position as param.

  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
        data() {
            return {
                handleId: "handle-id",
                draggableValue: { };
            }
        },
        mounted() {
            this.draggableValue.handle = this.$refs[this.handleId];
            this.draggableValue.onPositionChange = this.onPosChanged;
        },
        methods: {
            onPosChanged: function(pos) {
                console.log("left corner", pos.x);
                console.log("top corner", pos.y);
            }
        }
  ...
resetInitialPos

Type: Boolean
Required: false

stopDragging

Type: Boolean
Required: false

Keywords

FAQs

Package last updated on 10 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc