一、mapState方法获取vuex中的数据

当store中的数据比较多的时候,可以用这个函数去获取数据

  1. export default new Vuex.Store({
  2. state:{
  3. city:"武汉",
  4. name:"程超",
  5. sex:"男",
  6. age:20
  7. }
  8. })
  1. <template>
  2. <div class="home">
  3. <h1>首页</h1>
  4. <h2>{{city}}</h2>
  5. </div>
  6. </template>
  7. <script>
  8. import {mapState} from 'vuex';
  9. export default {
  10. computed:{
  11. ...mapState(['city','name','age','sex'])
  12. }
  13. }
  14. </script>