Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $route.query.page返回错误的值,或者返回';v-if条件下的s型铸造问题_Php_Laravel_Vue.js - Fatal编程技术网

Php $route.query.page返回错误的值,或者返回';v-if条件下的s型铸造问题

Php $route.query.page返回错误的值,或者返回';v-if条件下的s型铸造问题,php,laravel,vue.js,Php,Laravel,Vue.js,我正在做一个帖子页面,焦点是分页 我创建了一个分页组件,如下所示: <template> <nav aria-label="Pagination"> <ul class="pagination justify-content-end"> <li class="page-item" v-if="currentPage !== 1"> <a @click="previ

我正在做一个帖子页面,焦点是分页

我创建了一个分页组件,如下所示:

<template>
    <nav aria-label="Pagination">
        <ul class="pagination justify-content-end">
            <li class="page-item" v-if="currentPage !== 1">
                <a @click="previous" class="page-link" href="javascript:void(0)" tabindex="-1">Previous</a>
            </li>
            <li v-for="page in getNumberOfPagesShow"
                v-bind:class="{ disabled: page === currentPage }"
                class="page-item">
                <a @click="clickPage(page)" class="page-link" href="javascript:void(0)">
                    {{ page }}
                </a>
            </li>
            <li class="page-item" v-if="currentPage !== totalPages">
                <a @click="next" class="page-link" href="javascript:void(0)">Next</a>
            </li>
        </ul>
    </nav>

</template>

<script>
    export default {
        name: "pagination",
        props: ['app', 'onClickPage', 'totalPages', 'page'],
        data()
        {
            return {
                currentPage: this.page,
                lastPage: 0
            }
        },


        computed: {
            getNumberOfPagesShow()
            {
                if (this.totalPages > 10)
                {
                    return 10;
                }

                return this.totalPages;
            }
        },

        methods: {
            previous()
            {
                this.currentPage--;

                this.clickPage(this.currentPage);
            },

            next()
            {
                this.currentPage++;

                this.clickPage(this.currentPage);
            },

            clickPage(page)
            {
                this.currentPage = page;

                this.onClickPage(page);
            }
        }
    }
</script>

<style scoped>

</style>
如果当前页面为1,则应该隐藏上一个按钮。但是,这不起作用,这表明
app.$route.query.page
没有正确获取值

当我在
created()
方法中调试时,我编写

console.log(this.app.$route.query.page)
它确实返回正确的值。所以我不知道问题出在哪里。
提前谢谢你

太好了,解决方案是将prop
页面
解析为int:

    data()
    {
        return {
            currentPage: parseInt(this.page),
            lastPage: 0
        }
    },

尝试添加“@click.prevent=“previous”`并删除
href=“javascript:void(0)”
问题不在于单击按钮,而在于从这个.app.$route.query.pageyes获取当前页面的正确值,我知道,但我建议作为一种好的做法,但是有一点我不明白,那就是
onClickPage
property不要担心,关于点击工作的一切我都会在你创建的hook
console.log(typeof(this.app.$route.query.page))
中要求你这样做,然后在你的控制台中告诉我结果
console.log(this.app.$route.query.page)
    data()
    {
        return {
            currentPage: parseInt(this.page),
            lastPage: 0
        }
    },