index.js 592B

123456789101112131415161718192021222324
  1. export default {
  2. namespaced: true,
  3. state: {
  4. location: []
  5. },
  6. mutations: {
  7. init (state, data) { // 这里的state对应着上面这个state
  8. state.location = data
  9. }
  10. },
  11. actions: {
  12. updateLocationInfo (context) { // 这里的context和我们使用的$store拥有相同的对象和方法
  13. return new Promise((resolve) => {
  14. this.$ajax(this.$api.cms.location.url, {
  15. method: this.$api.cms.location.method
  16. }).then(res => {
  17. context.commit('init', res)
  18. resolve()
  19. })
  20. })
  21. }
  22. }
  23. }