Skip to content

Commit ad14a8a

Browse files
Solution for issue #647
1 parent 24f4c08 commit ad14a8a

File tree

4 files changed

+117
-9
lines changed

4 files changed

+117
-9
lines changed

example/components/functional.vue

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template>
2+
<div class="row">
3+
<div class="col-8">
4+
<h3>Draggable</h3>
5+
6+
<draggable
7+
v-model="rows"
8+
tag="v-layout"
9+
class="row wrap fill-height align-center sortable-list"
10+
style="background: grey;"
11+
>
12+
<v-flex
13+
v-for="row in rows"
14+
:key="row.index"
15+
class="sortable"
16+
xs12
17+
my-2
18+
style="background: red"
19+
>
20+
21+
<draggable
22+
:list="row.items"
23+
tag="v-layout"
24+
:group="{ name: 'row' }"
25+
class="row wrap justify-space-around"
26+
>
27+
<v-flex
28+
v-for="item in row.items"
29+
:key="item.title"
30+
xs4
31+
pa-3
32+
class="row"
33+
>
34+
<v-card style="height: 100px;">{{ item.title }}</v-card>
35+
</v-flex>
36+
</draggable>
37+
38+
</v-flex>
39+
</draggable>
40+
</div>
41+
42+
<rawDisplayer
43+
class="col-3"
44+
:value="rows"
45+
title="List"
46+
/>
47+
</div>
48+
</template>
49+
50+
<script>
51+
import draggable from "@/vuedraggable";
52+
import Vue from "vue";
53+
import Vuetify from "vuetify";
54+
import "vuetify/dist/vuetify.min.css";
55+
56+
Vue.use(Vuetify);
57+
58+
export default {
59+
name: "functional",
60+
display: "Functional third party",
61+
order: 17,
62+
components: {
63+
draggable
64+
},
65+
data() {
66+
return {
67+
enabled: true,
68+
rows: [
69+
{
70+
index: 1,
71+
items: [
72+
{
73+
title: "item 1"
74+
}
75+
]
76+
},
77+
{
78+
index: 2,
79+
items: [
80+
{
81+
title: "item 2",
82+
},
83+
{
84+
title: "item 3"
85+
}
86+
]
87+
}
88+
]
89+
};
90+
}
91+
};
92+
</script>
93+
<style scoped>
94+
.buttons {
95+
margin-top: 35px;
96+
}
97+
98+
.ghost {
99+
opacity: 0.5;
100+
background: #c8ebfb;
101+
}
102+
</style>

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"vue-router": "^3.0.2",
5252
"vue-server-renderer": "^2.6.8",
5353
"vue-template-compiler": "^2.6.8",
54+
"vuetify": "^1.5.16",
5455
"vuex": "^3.1.1"
5556
},
5657
"eslintConfig": {

src/vuedraggable.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ const draggableComponent = {
146146
data() {
147147
return {
148148
transitionMode: false,
149-
noneFunctionalComponentMode: false,
150-
init: false
149+
noneFunctionalComponentMode: false
151150
};
152151
},
153152

@@ -186,7 +185,8 @@ const draggableComponent = {
186185

187186
mounted() {
188187
this.noneFunctionalComponentMode =
189-
this.getTag().toLowerCase() !== this.$el.nodeName.toLowerCase();
188+
this.getTag().toLowerCase() !== this.$el.nodeName.toLowerCase() &&
189+
!this.getIsFunctional();
190190
if (this.noneFunctionalComponentMode && this.transitionMode) {
191191
throw new Error(
192192
`Transition-group inside component is not supported. Please alter tag value or remove transition-group. Current tag value: ${this.getTag()}`
@@ -251,6 +251,11 @@ const draggableComponent = {
251251
},
252252

253253
methods: {
254+
getIsFunctional() {
255+
const { fnOptions } = this._vnode;
256+
return fnOptions && fnOptions.functional;
257+
},
258+
254259
getTag() {
255260
return this.tag || this.element;
256261
},
@@ -265,12 +270,6 @@ const draggableComponent = {
265270
},
266271

267272
getChildrenNodes() {
268-
if (!this.init) {
269-
this.noneFunctionalComponentMode =
270-
this.noneFunctionalComponentMode && this.$children.length === 1;
271-
this.init = true;
272-
}
273-
274273
if (this.noneFunctionalComponentMode) {
275274
return this.$children[0].$slots.default;
276275
}

0 commit comments

Comments
 (0)