Newer
Older
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
<script setup>
import CircularCard from "./components/CircularCard.vue";
import DragGrid from "../../src/DragGrid.vue";
</script>
<template>
<div class="ttt-container">
<DragGrid
:rows="3"
:cols="3"
v-model="ticTacToe1"
class="tic-tac-toe"
context="ticTacToe"
:validate-element="randomKey"
>
<template #item="item">
<CircularCard>
{{ item.key.startsWith("a") ? "X" : "O" }}
</CircularCard>
</template>
</DragGrid>
<div>
<p>
These two are two different grids but we can drag from right to left!
</p>
<p>Drag items from the container on the right to play on the left.</p>
</div>
<DragGrid
:rows="1"
:cols="2"
v-model="ticTacToe2"
class="tic-tac-toe"
context="ticTacToe"
:pos-validation="blockAllMoving"
>
<template #item="item">
<CircularCard>
{{ item.data.text }}
</CircularCard>
</template>
</DragGrid>
</div>
</template>
<script>
export default {
name: "Example2TicTacToe",
methods: {
blockAllMoving() {
return false;
},
randomKey(element) {
if (element.key.length !== 1) return;
element.key += Math.random().toString(36).replace("0.", "");
},
},
data() {
return {
ticTacToe1: [
{ x: 1, y: 1, w: 1, h: 1, key: "a1", data: { text: "X" } },
{ x: 3, y: 3, w: 1, h: 1, key: "b1", data: { text: "O" } },
],
ticTacToe2: [
{ x: 1, y: 1, w: 1, h: 1, key: "a", data: { text: "X" } },
{ x: 2, y: 1, w: 1, h: 1, key: "b", data: { text: "O" } },
],
};
},
};
</script>
<style scoped>
.tic-tac-toe {
max-width: 400px;
}
.ttt-container {
display: flex;
justify-content: space-between;
}
</style>