File tree 2 files changed +36
-26
lines changed
2 files changed +36
-26
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <div id =" nav" >
3
- <router-link to =" /" >Home</router-link > |
4
- <router-link to =" /about" >About</router-link >
5
- </div >
6
- <router-view />
2
+ <button @click =" increment" >Click</button >
3
+ <div v-if =" count % 2 === 0" >Count: {{ count }}. Count is even.</div >
4
+ <div v-if =" count % 2 !== 0" >Count: {{ count }}. Count is odd.</div >
7
5
</template >
8
6
7
+ <script >
8
+ import { computed } from " vue" ;
9
+ import { useStore } from " vuex" ;
10
+ export default {
11
+ setup () {
12
+ const store = useStore ();
13
+ const count = computed (() => store .state .count );
14
+ const increment = () => {
15
+ store .commit (" increment" );
16
+ };
17
+
18
+ return { count, increment };
19
+ },
20
+ };
21
+ </script >
22
+
9
23
<style >
10
24
#app {
11
25
font-family : Avenir, Helvetica , Arial , sans-serif ;
Original file line number Diff line number Diff line change 1
1
import { mount } from "@vue/test-utils" ;
2
- import { ref } from "vue" ;
2
+ import App from "@/App.vue" ;
3
+ import { createStore } from "vuex" ;
3
4
4
- const App = {
5
- setup ( ) {
6
- const count = ref ( 0 ) ;
7
- const increment = ( ) => ( count . value += 1 ) ;
8
-
9
- return { count, increment } ;
10
- } ,
11
- template : `
12
- <button @click="increment"></button>
13
- <div v-if="count % 2 === 0">
14
- Count: {{ count }}. Count is even.
15
- </div>
16
-
17
- <div v-if="count % 2 !== 0">
18
- Count: {{ count }}. Count is odd.
19
- </div>
20
- ` ,
5
+ const createVuexStore = ( ) => {
6
+ return createStore ( {
7
+ state : ( ) => ( {
8
+ count : 0 ,
9
+ } ) ,
10
+ mutations : {
11
+ increment ( state ) {
12
+ state . count += 1 ;
13
+ } ,
14
+ } ,
15
+ } ) ;
21
16
} ;
22
17
23
- function factory ( { data } = { data : { } } ) {
18
+ function factory ( ) {
19
+ const store = createVuexStore ( ) ;
24
20
return mount ( App , {
25
- data ( ) {
26
- return data ;
21
+ global : {
22
+ plugins : [ store ] ,
27
23
} ,
28
24
} ) ;
29
25
}
You can’t perform that action at this time.
0 commit comments