forked from Jexordexan/vue-slicksort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (86 loc) · 2.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import Vue from 'vue';
import range from 'lodash/range';
import random from 'lodash/random';
import { ContainerMixin, ElementMixin } from './src';
const SortableList = {
mixins: [ContainerMixin],
template: `
<ul class="list">
<slot />
</ul>
`,
};
const SortableItem = {
mixins: [ElementMixin],
props: ['item'],
template: `
<li class="list-item" :style="{height: item.height + 'px'}" >{{item.value}}</li>
`,
};
let id = 100;
const InnerList = {
mixins: [ElementMixin],
props: ['list'],
template: `
<li class="list-item">
<h3>{{list.name}}</h3>
<SortableList v-model="list.items" class="shortList">
<SortableItem v-for="(item, index) in list.items" :key="item.id" :collection="list.name" :index="index" :item="item" />
</SortableList>
</li>
`,
components: {
SortableItem,
SortableList,
},
data() {
return {
items: this.list.items.slice(0),
};
},
};
const ExampleVue = {
name: 'Example',
template: `
<div class="root">
<SortableList lockAxis="y" v-model="items">
<SortableItem v-for="(item, index) in items" :key="index" :index="index" collection="items" :item="item" />
</SortableList>
<SortableList lockAxis="y" v-model="lists">
<InnerList v-for="(list, index) in lists" :key="list.name" :index="index" collection="lists" :list="list" ></InnerList>
</SortableList>
</div>
`,
components: {
SortableItem,
SortableList,
InnerList,
},
data() {
return {
items: range(100).map((value) => {
return {
value: 'Item ' + (value + 1),
height: random(49, 120),
id: id++,
};
}),
lists: range(3).map(val => {
return {
id: id++,
name: 'List ' + (val + 1),
items: range(3).map((value) => {
return {
value: 'Item ' + (value + 1),
id: id++,
};
}),
};
}),
};
},
};
new Vue({
el: '#root',
render: (h) => h(ExampleVue),
});