vuex文件:
ThemeVuex.ts
import { Commit } from 'vuex'
const state: any = {
/** 当前主题 */
currentTheme: 0
}
const mutations: any = {
SET_CURRENT_THEME(state1: any, v: any) {
state1.currentTheme = v
}
}
const actions: any = {
setCurrentTheme(context: { commit: Commit }, val: any) {
context.commit('SET_CURRENT_THEME', val)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}
store\index.ts
import Vue from 'vue'
import Vuex from 'vuex'
import ThemeVuex from './ThemeVuex'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
ThemeVuex
}
})
使用vuex的ts组件:
store.commit('ThemeVuex/SET_CURRENT_THEME',id)