Vue js2 How to use mixins with axios request?
How can i import a method from an external file on vue js and to use mehods from there, but with different axios call?
For example: I have a vue js 2 & laravel web app and i use axios to fetch data from backend like this
UserComponent.vue
methods: {
getData() {
this.$Progress.start()
this.loading = true
axios.get('/admin/users/getusers',
{
params: {
'&page': this.pagination.current_page,
'&perPage': this.displayRecord,
}
})
.then(response => {
this.users = response.data.data
this.pagination = response.data.meta
this.loading = false
this.$Progress.finish()
// console.log(response)
})
},
}
Is there any option i can export this method on another file
Functions.vue
methods: {
getData() {
this.$Progress.start()
this.loading = true
axios.get('This need to pass from parent',
{
params: {
'&page': this.pagination.current_page,
'&perPage': this.displayRecord,
'&filterName': this.filterName
}
})
.then(response => {
this.users = response.data.data
this.pagination = response.data.meta
this.loading = false
this.$Progress.finish()
// console.log(response)
})
},
}
and to call this file on my UserComponent.vue but with diferent axios url. For each component to use different url. Like props on vue template?
@Leon012 It's a very simplified example because I don't have access to your API or your entire code (including loading logic, pagination logic and filters logic), but it should put you on the right track.
https://codesandbox.io/s/jovial-swanson-ftctj2?file=/src/App.vue
Please or to participate in this conversation.