I inherited some code and I'm having issues refactoring.
The script can successfully paginate data from a get request, as well as run a search query and paginate the result subset. However, when trying to change the page, the script forgets the search query and reverts to the entire get request.
I see where the issue is occuring but as a vue js novice I'm having issue combining the functions
Changing the page is control in this way:
<div class="card-footer">
<pagination :data="userToTests" :limit=5 @pagination-change-page="getResults"></pagination>
</div>
moving through the pages so
methods:{
// Our method to GET results from a Laravel endpoint
getResults(page = 1) {
this.$Progress.start()
axios.get(base_path+'/admin_api/userToTest?page=' + page)
.then(response => {
this.userToTests = response.data;
this.$Progress.finish()
}).catch(error=>{
this.$Progress.fail()
});
},
}
And running a search query
created(){
Fire.$on('searching',()=>{
let query=this.$parent.search;
axios.get(base_path+'/admin_api/findFeedback?q='+ query)
.then((data)=>{
this.userToTests = data.data;
})
.catch(()=>{
})
})
}
What would be the most elegent way of using getResults when no search query is entered, but keeping an existing query while moving through the pages?
Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…