unit.js 586 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { getList } from '@/api/unit'
  2. const getDefaultState = () => {
  3. return {
  4. units: []
  5. }
  6. }
  7. const state = getDefaultState()
  8. const mutations = {
  9. SET_UNITS: (state, units) => {
  10. state.units = units
  11. }
  12. }
  13. const actions = {
  14. // get units
  15. getUtils({ commit, state }) {
  16. return new Promise((resolve, reject) => {
  17. getList().then(response => {
  18. commit('SET_UNITS', response.data.list)
  19. resolve(response.data)
  20. }).catch(error => {
  21. reject(error)
  22. })
  23. })
  24. }
  25. }
  26. export default {
  27. namespaced: true,
  28. state,
  29. mutations,
  30. actions
  31. }