5.26

在这篇博客中,我将介绍Vuex,它是Vue.js的状态管理模式和库。Vuex 专注于应用的所有组件的状态管理。
安装Vuex:

vue add vuex
定义store:

// src/store/index.js
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++;
}
},
actions: {
increment({ commit }) {
commit('increment');
}
},
modules: {}
});

posted @ 2025-05-26 23:32  Echosssss  阅读(3)  评论(0)    收藏  举报