【问题标题】:vuejs Pagination GET Url Paramsvuejs 分页获取 URL 参数
【发布时间】:2019-09-20 20:50:11
【问题描述】:

我正在使用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;

}

【问题讨论】:

    标签: vue.js laravel-5


    【解决方案1】:
    axios.get('api/findByCategoy?category=' + e.target.value + '&page=1')
    

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

    【讨论】:

    • 可能要编码URIComponent e.target.value;或者,axios.get('api/findByCategoy', {params: { page: page, category: e.target.value }})
    猜你喜欢
    • 2011-07-20
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2015-02-15
    • 2018-03-29
    • 1970-01-01
    相关资源
    最近更新 更多