File tree Expand file tree Collapse file tree 2 files changed +36
-26
lines changed Expand file tree Collapse file tree 2 files changed +36
-26
lines changed Original file line number Diff line number Diff line change 11<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 >
75</template >
86
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+
923<style >
1024#app {
1125 font-family : Avenir, Helvetica , Arial , sans-serif ;
Original file line number Diff line number Diff line change 11import { mount } from "@vue/test-utils" ;
2- import { ref } from "vue" ;
2+ import App from "@/App.vue" ;
3+ import { createStore } from "vuex" ;
34
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+ } ) ;
2116} ;
2217
23- function factory ( { data } = { data : { } } ) {
18+ function factory ( ) {
19+ const store = createVuexStore ( ) ;
2420 return mount ( App , {
25- data ( ) {
26- return data ;
21+ global : {
22+ plugins : [ store ] ,
2723 } ,
2824 } ) ;
2925}
You can’t perform that action at this time.
0 commit comments