Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sagalbot/vue-sortable

A lightweight directive for reorderable drag-and-drop lists using RubaXa/Sortable
https://github.com/sagalbot/vue-sortable

Last synced: 4 months ago
JSON representation

A lightweight directive for reorderable drag-and-drop lists using RubaXa/Sortable

Awesome Lists containing this project

README

        

# Vue Sortable [![Build Status](https://travis-ci.org/sagalbot/vue-sortable.svg?branch=master)](https://travis-ci.org/sagalbot/vue-sortable)

> Easily add drag-and-drop sorting to your Vue.js applications without jQuery, using the v-sortable directive, a thin wrapper for the minimalist [RubaXa/SortableJS](https://github.com/RubaXa/Sortable) library.

##### [View Live Demo & Docs](http://sagalbot.github.io/vue-sortable/)

Installation
--

#### NPM

```bash
npm install vue-sortable
```

Setup

```javascript
import Vue from 'vue'
import Sortable from 'vue-sortable'

Vue.use(Sortable)
```

#### Browser Globals

If you aren't using a build system, you probably just want to include a `` tag and keep things simple. `unpkg.com` serves as a CDN for NPM projects. You can grab `vue-sortable` from unpkg in a couple ways:

- `<script src="https://unpkg.com/[email protected]"> # use a specific version`
- ` # use the latest version`

Note that you will need to include `RubaXa/Sortable` & `Vue` before including `vue-sortable`.

[View Live Example](http://jsbin.com/vasogus/edit?html,js,console,output)

```html







  • Foo

  • Bar

  • Baz



new Vue({
el: 'body'
});

```

Common Use Cases
--

#### Update Source Data Order

The below implementation will update the order of the source data after an item is sorted using the `sortable` `onUpdate` callback.

[View Live Example](http://jsbin.com/cicewo/edit?html,js,output)

```
new Vue({
el: 'body',
data: {
list: ['Foo', 'Bar', 'Baz']
},
methods: {
onUpdate: function (event) {
this.list.splice(event.newIndex, 0, this.list.splice(event.oldIndex, 1)[0])
}
}
});
```

```


  • {{ item }}


```

Contributing
--

I'd like to keep this directive as simple as possible, but if there's something you'd like to see added feel free to submit a PR.

The plugin is built using the vue-cli [webpack-simple template](https://github.com/vuejs-templates/webpack-simple).

``` bash
# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for demo site
npm run build
```

For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).