💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) // 相当于data对象的状态对象 const state = { count: 0 //指定初始化数据 } // 包含多个更新状态的方法的对象 const mutations = { INCREMENT (state) { state.count ++ }, DECREMENT (state) { state.count -- } } // 包含多个间接更新状态的方法的对象 const actions = { increment ({commit}) { commit('INCREMENT') }, decrement ({commit}) { commit('DECREMENT') }, incrementIfOdd ({commit, state}) { if(state.count%2===1){ commit('INCREMENT') } }, incrementAsync ({commit}) { setTimeout(()=>{ commit('INCREMENT') }, 1000) } } // 包含多个getters计算属性的对象 const getters = { evenOrOdd (state) { return state.count % 2 ? '偶数' : '奇数' } } export default new Vuex.Store({ state, mutations, actions, getters }) ~~~