vuex getters

<p>square: {{$store.getters.squareCount}}</p>

index.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 10
  },
  mutations: {
  },
  actions: {
  },
  getters: {
    squareCount(state) {
      return state.count * state.count;
    }
  },
  modules: {
  }
})

export default store

posted @ 2021-07-14 19:03  thomas_blog  阅读(27)  评论(0编辑  收藏  举报