Skip to content

Commit 60a6ed4

Browse files
Adding footer slot+ Fix for issue #164 (computing visible index with animation)
1 parent f913c52 commit 60a6ed4

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

examples/footerslot.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!doctype html>
2+
<html class="no-js" lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<title>Basic example</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
10+
<link rel="stylesheet" href="css/main.css">
11+
</head>
12+
<body>
13+
14+
<div id="main">
15+
<h1>Vue Draggable</h1>
16+
17+
<div :class="dragging? 'list-dragging' : 'drag'">
18+
<h2>Draggable</h2>
19+
<draggable :list="list" @start="dragging=true" @end="dragging=false" :options="{draggable:'.itemd'}">
20+
<div v-for="element in list" class="itemd" :key="element.id">{{element.name}}</div>
21+
<button slot="footer" @click="add">Add People</button>
22+
</draggable>
23+
</div>
24+
25+
<div class="normal">
26+
<h2>Normal v-for</h2>
27+
<div >
28+
<div v-for="element in list">{{element.name}}</div>
29+
</div>
30+
</div>
31+
32+
<button @click="replace">Replace</button>
33+
<br>
34+
35+
<a href="Two_Lists.html">See 2 lists example</a>
36+
<a href="Two_Lists_Clone.html">See clone element example</a>
37+
<a href="Two_Lists_Clone_If.html">See clone v-if element example</a>
38+
39+
</div>
40+
41+
<script type="text/javascript" src="libs\vue\dist\vue.js"></script>
42+
<script type="text/javascript" src="libs\Sortable\Sortable.js"></script>
43+
<script type="text/javascript" src="src\vuedraggable.js"></script>
44+
<script type="text/javascript" src="script\main.js"></script>
45+
</body>
46+
</html>

examples/script/main.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
var id=2;
2+
13
var vm = new Vue({
24
el: "#main",
35
data: {
4-
list: [ {name: "John"},
5-
{name: "Joao"},
6-
{name: "Jean"} ],
6+
list: [ {name: "John", id:0},
7+
{name: "Joao", id:1},
8+
{name: "Jean", id:2} ],
79
dragging: false
810
},
911
methods:{
1012
add: function(){
11-
this.list.push({name:'Juan'});
13+
this.list.push({name:'Juan '+id, id: id++});
1214
},
1315
replace: function(){
14-
this.list=[{name:'Edgard'}]
16+
this.list=[{name:'Edgard', id: id++}]
1517
}
1618
}
1719
});

src/vuedraggable.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
}
1414

1515
function insertNodeAt(fatherNode, node, position) {
16-
if (position < fatherNode.children.length) {
17-
fatherNode.insertBefore(node, fatherNode.children[position])
18-
} else {
19-
fatherNode.appendChild(node)
20-
}
16+
const refNode = (position ===0) ? fatherNode.children[0] : fatherNode.children[position-1].nextSibling
17+
fatherNode.insertBefore(node, refNode)
2118
}
2219

2320
function computeVmIndex(vnodes, element) {
@@ -95,13 +92,19 @@
9592
},
9693

9794
render(h) {
98-
if (this.$slots.default && this.$slots.default.length === 1) {
99-
const child = this.$slots.default[0]
95+
const slots = this.$slots.default
96+
if (slots && slots.length === 1) {
97+
const child = slots[0]
10098
if (child.componentOptions && child.componentOptions.tag === "transition-group") {
10199
this.transitionMode = true
102100
}
103101
}
104-
return h(this.element, null, this.$slots.default);
102+
let children = [...slots]
103+
const {footer} = this.$slots
104+
if (footer){
105+
children = [...slots, ...footer]
106+
}
107+
return h(this.element, null, children);
105108
},
106109

107110
mounted() {

0 commit comments

Comments
 (0)