Skip to content

Commit 07f0a50

Browse files
committed
Merge branch 'main' of github.com:bencodezen/vue-3-lab into main
2 parents 49ccdf6 + 5bf5cce commit 07f0a50

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/views/Home.vue

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1+
<template>
2+
<div class="home">
3+
<img alt="Vue logo" src="../assets/logo.png" />
4+
<p>{{ count }}</p>
5+
<button @click="incrementCount">Add</button>
6+
</div>
7+
</template>
8+
19
<script>
2-
import useStore from '../features/useStore'
10+
import { reactive, toRefs, watch } from 'vue'
311
412
export default {
13+
name: 'Home',
514
setup() {
6-
const { state, changeCount } = useStore
15+
const state = reactive({
16+
count: 0
17+
})
18+
19+
const incrementCount = () => {
20+
state.count++
21+
}
722
8-
console.log(state)
23+
watch(
24+
() => state.count,
25+
(currentValue, oldValue) => {
26+
console.log('current', currentValue)
27+
console.log('old', oldValue)
28+
}
29+
)
30+
31+
const
932
1033
return {
11-
state,
12-
changeCount
34+
...toRefs(state),
35+
incrementCount
1336
}
1437
}
1538
}
1639
</script>
17-
18-
<template>
19-
<h1>Counter</h1>
20-
<p>{{ state.count }}</p>
21-
<button @click="changeCount">Change Count</button>
22-
</template>

0 commit comments

Comments
 (0)