File tree 1 file changed +28
-11
lines changed
1 file changed +28
-11
lines changed Original file line number Diff line number Diff line change
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
+
1
9
<script >
2
- import useStore from ' ../features/useStore '
10
+ import { reactive , toRefs , watch } from ' vue '
3
11
4
12
export default {
13
+ name: ' Home' ,
5
14
setup () {
6
- const { state , changeCount } = useStore
15
+ const state = reactive ({
16
+ count: 0
17
+ })
18
+
19
+ const incrementCount = () => {
20
+ state .count ++
21
+ }
7
22
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
9
32
10
33
return {
11
- state,
12
- changeCount
34
+ ... toRefs ( state) ,
35
+ incrementCount
13
36
}
14
37
}
15
38
}
16
39
</script >
17
-
18
- <template >
19
- <h1 >Counter</h1 >
20
- <p >{{ state.count }}</p >
21
- <button @click =" changeCount" >Change Count</button >
22
- </template >
You can’t perform that action at this time.
0 commit comments