State
jsx
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
num: 10,
},
});
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
vue
<template>
<div>
<p>{{ $store.state.num }}</p>
<p>{{ num }}</p>
</div>
</template>
<script>
export default {
data() {
return {};
},
computed: {
num() {
return this.$store.state.num;
},
},
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19