I am exporting a function to another file that is as a webpack-simple + vuejs component, This is the function of api-user.js file:
export function getUsers () {
axios.post('/api/get_list',{})
.then(req => {return req.data.list;})
.catch(err => console.log(err))
}
In the myComponent.vue file, I'm importing it and calling it:
created: async function () {
this.arrayUsers = await getUsers()
console.log(this.arrayUsers)
},
But I just get undefined , and I'm not quite sure why.
An example of what I'm trying to do:
EDIT:
I've got it in a way here, but it's not what I want yet, because it requires a lot of code in the file which I'm trying to keep clean.
api-user.js:
export function getUsers () {
return axios.post('/apiminer/get_list',{})
}
mycomponent.vue:
created: function() {
getUsers().then((res) => {
this.arrayUsers= res.data.list
})
},