一、computed
export default new Vuex.Store({state: {count:1,city:"武汉",name:"vuex",age:4},mutations: {},modules: {}})
<script>export default {name: 'Home',computed:{state(){return this.$store.state;}}}</script>
二、mapState获取vuex中的数据
当组件要使用vuex中的多条数据的时候,可以使用这个函数去获取数据
export default new Vuex.Store({state: {count:1,city:"武汉",name:"vuex",age:4},mutations: {},modules: {}})
<script>import {mapState} from 'vuex'export default {name: 'Home',computed:{...mapState(["city","name","age"])}}</script>
