Vuex getters的使用
1、当state中的数据需要加工使用时,可以使用getters加工
2、在sindex.js中追加getters配置,注意别忘记创建和暴露
//准备state对象--保存具体数据 const state = { sum:0 } // 对state中的数据进行加工处理 const getters = { bigSum(state){ return state.sum * 10 } } //创建并暴露store export default new Vuex.Store({ actions, mutations, state, getters })
3、组件中读取数据
$store.getters.bigSum

浙公网安备 33010602011771号