logo

该视频仅会员有权观看

立即开通课程「Vue.js前端应用开发实践」权限。

¥
199
/ 年

动作的 Context 参数

  • View store actions support a parameter like text x.
  • You can inspect this parameter to see its contents.
  • In the gts name action, you can output its context to the console and check it in the browser's console.
  • The context parameter contains a commit method, which is used to commit mutations to modify store data.
  • There is also a dispatch method to dispatch other actions within the store.
  • Inside the store, there are getters (like one called name) and root getters for accessing the store's data.
  • When stores are modular, each module may have its own state and getters.
  • rules state represents the combined state of all store modules.
  • The state referred to at the end is the current module's state.
  • If you only want to use some parts of the context in an action, you can destructure it into an object.
  • By adding commit to the object, you can directly use the commit method within the action.