main.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
count: 0,
msg: 'hello world',
num: 11,
val: 12
},
mutations: {
addNum(state) {
state.count++
},
setNum(state, val) {
state.num = val
}
},
actions: {
},
modules: {
},
getters: {
}
})
state.vue
<template>
<div>
<h1>msg: {{msg}}</h1>
<h3>num: {{num}}</h3>
<h3>val: {{val}}</h3>
<input type="text" v-model="resolve">
<input type="text" :value="num" @change="changeValue">
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: "state",
data() {
return {
nums: 'abc'
}
},
computed: {
resolve: function () {
return this.nums.split('').reverse().join('')
},
...mapState({
msg: 'msg',
num: (state) => state.num,
val: function(state) {
return this.nums + state.val
}
})
}
}
</script>
<style scoped>
</style>