One of the challenges I'm facing is trying to call axios using this.request(url)
within a mixin. The goal is to streamline and consolidate all axios-related functionality in a single file, but I'm running into some issues.
In my 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 issue I'm encountering is that the employees variable appears as "undefined."
I suspect that the problem lies with asynchronous processing or the concept of async/await, but I'm still grappling with understanding it fully.