Counter.vue
654 Bytes
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
<template>
<view>
<text class="title">{{ counter.count }}</text>
<view class="button" @tap="onAdd">ADD</view>
</view>
</template>
<script>
import { useCounterStore } from '../stores/counter'
export default {
setup() {
const counter = useCounterStore()
const onAdd = () => {
counter.count++
// with autocompletion ✨
// counter.$patch({count: counter.count + 1})
// or using an action instead
// counter.increment()
}
return {
counter,
onAdd
}
}
}
</script>
<style>
.title {
font-size: 32px;
}
.button {
border: 1px solid lightgray;
padding: 5px 10px;
}
</style>