Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

laravel - Paginating a search query on vuejs

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...