Skip to content

Instantly share code, notes, and snippets.

@liaooliver
Created June 30, 2020 05:59
Show Gist options
  • Save liaooliver/be7831623c921a91f4328263a7c2b946 to your computer and use it in GitHub Desktop.
Save liaooliver/be7831623c921a91f4328263a7c2b946 to your computer and use it in GitHub Desktop.
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
actions: {
// actions 中有兩個函式 changeColor & changeTextContent
// 這兩個函式上都有做一件事情 => context.commit()
// context.commit()這個函式的作用是呼叫 Mutations function 執行改變 state 狀態
changeColor(context, payload) {
console.log("檢查 context 的內容有哪些東西:", context);
context.commit("changeColor", payload);
},
changeTextContent(context, payload) {
context.commit("changeTextContent", payload);
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment