import Axios from axios const state profiles null profile null const a

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Axios from 'axios'
const state = {
profiles: null,
profile: null
}
const actions = {
// Загружаем один профайл по id
loadProfileOnce: async ({commit}, id) => {
commit('clearError')
commit('clearMessage')
commit('setLoading', true)
try {
const {data} = await Axios.get('http://localhost:3001/api/profile/' + id, {
withCredentials: true
})
if (data.profile) {
console.log(data.profile)
commit('loadProfileOnce', data.profile)
commit('setMessage', data.message)
}
commit('setLoading', false)
} catch (error) {
commit('setLoading', false)
commit('setError', error.message)
throw error
}
},
// Загружаем профайлы на dashboard
loadProfiles: async ({commit}) => {
commit('clearError')
commit('clearMessage')
commit('setLoading', true)
try {
const {data} = await Axios.get('http://localhost:3001/api/profile/', {
withCredentials: true
})
if (data.profiles) {
commit('loadProfiles', data.profiles)
commit('setMessage', data.message)
}
commit('setLoading', false)
} catch (error) {
commit('setLoading', false)
commit('setError', error.message)
throw error
}
}
}
const mutations = {
loadProfiles: (state, payload) => {
state.profiles = payload
},
loadProfileOnce: (state, payload) => {
state.profile = payload
}
}
const getters = {
getProfiles: (state) => {
return state.profiles
},
getOneProfile: (state) => {
return state.profile
}
}
export default {
state,
getters,
actions,
mutations
}