vuejs分页GET网址参数

时间:2019-05-02 10:39:48

标签: vue.js laravel-5

我正在使用https://github.com/gilbitron/laravel-vue-pagination分页,效果很好。我在页面中包含了分页,如下所示:

<pagination :data="posts" @pagination-change-page="getResults"></pagination>

和方法

        getResults(page = 1) {
                    axios.get('api/post?page=' + page)
                        .then(response => {
                            this.posts = response.data;
                        });
            },  

现在,当我按类别搜索时,分页链接显示api / findByCategoy?category = 5&page = 1

        selectCatgory(e) {
                   axios.get('api/findByCategoy?category=' + e.target.value)
                    .then((data) => {
                        this.posts = data.data
                    })
                    .catch(() => {

                    })
        },

我在url中加入了GET参数。如何在getResults中更改路径

public function searchByCategory(){

    if ($search = \Request::get('category')) {
        $posts = Post::where('category_id',$search)->orderBy('created_at','desc')->paginate(20);
        $querystringArray = Input::only(['category']);
        $posts->appends($querystringArray);
    }else{
        $posts = Post::latest()->paginate(10);
    }

    return $posts;

}

1 个答案:

答案 0 :(得分:0)

axios.get('api/findByCategoy?category=' + e.target.value + '&page=1')

https://en.wikipedia.org/wiki/Query_string