/
Container.vue
73 lines (68 loc) · 1.88 KB
/
Container.vue
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
<template>
<div>
<div style="overflow: hidden; clear: both">
<Dustbin v-for="(dustbin, index) in dustbins"
v-bind:accepts="dustbin.accepts"
v-bind:lastDroppedItem="dustbin.lastDroppedItem"
v-on="{ drop: handleDrop(index) }"
v-bind:key="index" />
</div>
<div style="overflow: hidden, clear: both">
<Box v-for="(box, index) in boxes"
v-bind:name="box.name"
v-bind:type="box.type"
v-bind:isDropped="isDropped(box.name)"
v-bind:key="index" />
</div>
</div>
</template>
<script>
import Dustbin from './Dustbin'
import Box from './Box'
import ItemTypes from './ItemTypes'
import { DragDropContext } from 'vue-react-dnd'
import HTML5Backend, { NativeTypes } from 'react-dnd-html5-backend'
export default {
name: 'container',
components: {
Dustbin,
Box
},
mixins: [DragDropContext(HTML5Backend)],
data () {
return {
dustbins: [
{ accepts: [ItemTypes.GLASS], lastDroppedItem: null },
{ accepts: [ItemTypes.FOOD], lastDroppedItem: null },
{
accepts: [ItemTypes.PAPER, ItemTypes.GLASS, NativeTypes.URL],
lastDroppedItem: null
},
{ accepts: [ItemTypes.PAPER, NativeTypes.FILE], lastDroppedItem: null }
],
boxes: [
{ name: 'Bottle', type: ItemTypes.GLASS },
{ name: 'Banana', type: ItemTypes.FOOD },
{ name: 'Magazine', type: ItemTypes.PAPER }
],
droppedBoxNames: []
}
},
methods: {
isDropped (boxName) {
return this.droppedBoxNames.indexOf(boxName) > -1
},
handleDrop (index) {
return function (item) {
const { name } = item
this.dustbins[index].lastDroppedItem = item
if (name) {
this.droppedBoxNames.push(name)
}
}.bind(this)
}
}
}
</script>
<style lang="scss">
</style>