简体   繁体   English

vuejs-paginate - 按下导航栏品牌时切换到第 1 页活动 class

[英]vuejs-paginate - switch to page 1 active class when pressing the navbar brand

I'm using this handy pagination tool called vuejs-paginate and it works just fine in terms of functionality when I click each individual page item , but when I press the navbar brand (which switches to page 1), the pagination tool does not switch the active class to page 1 and the active class just remains on the page you were previously at.我正在使用这个名为vuejs-paginate 的方便的分页工具,当我单击每个单独的页面项目时,它在功能方面工作得很好,但是当我按下导航栏品牌(切换到第 1 页)时,分页工具不会切换活动 class 到第 1 页,活动 class 只保留在您之前所在的页面上。

Here's my pagination code:这是我的分页代码:

<template>
    <section role="region" class="paginate py-md-5 py-4" id="paginate">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <paginate
                        :page-count="20"
                        :click-handler="clickCallback"
                        :prev-text="'<'"
                        :next-text="'>'"
                        :container-class="'pagination'"
                        :page-class="'page-item'"
                        :page-link-class="'page-link'"
                        :next-class="'page-item'"
                        :next-link-class="'page-link'"
                        :prev-class="'page-item'"
                        :prev-link-class="'page-link'"
                        class="justify-content-center mb-0"
                    >
                    </paginate>
                </div>
            </div>
        </div>
    </section>
</template>

<script>
export default {
    methods: {
        clickCallback(pageNum) {
            this.$router.push({
                path: `/page/${pageNum}`
            })
        }
    }
}
</script>

<style lang="scss">

</style>

I was thinking of using some sort of way to programmatically click the first page item of the pagination when clicking on the navbar brand, but I'm not sure how to achieve this.在单击导航栏品牌时,我正在考虑使用某种方式以编程方式单击分页的第一页项目,但我不知道如何实现这一点。 Thanks for the help!谢谢您的帮助!

After a lot of debugging, I found out that it was actually where I had placed my pagination component.经过大量调试,我发现它实际上我放置分页组件的地方。 In my Nuxt app, I had put it inside default layouts .在我的 Nuxt 应用程序中,我把它放在了 default layouts中。 This means that when I had clicked on the navbar brand to go to the first page, the pagination did not remount .这意味着当我点击导航栏品牌到 go 到第一页时,分页没有重新安装 So what I did to resolve the problem was to transfer my pagination component to its individual pages .所以我为解决这个问题所做的就是将我的分页组件转移到它的各个页面 Now, when I switch from route to route, the active class will change because the pagination component remounts to react to the changes.现在,当我从一个路由切换到另一个路由时,活动的 class 将发生变化,因为分页组件会重新安装以对更改做出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM