I would like to call axios with this.request(url) from a mixin (to simplify and centralize everything about axios in the same file) but it's not working.
Vue file:
export default {
name: "employees-list",
data() {
return {
employees: []
}
},
mounted() {
this.employees = this.request('https://jsonplaceholder.typicode.com/posts');
}
}
Request.js
Vue.mixin({
methods: {
request: function (url) {
axios.get(url)
.then(response => {
return response.data
})
.catch(e => {
this.errors.push(e)
})
}
}
});
The employees is "undefined".
I think the problem is async or await but i don't understand.