简体   繁体   中英

Swiper - Next and prev buttons do not work

I'm trying to display a horizontal timeline on my HTML page. I'm having trouble with my swiper slider, the next and prev buttons do not work at all, I've included the library as well, still doesn't work, I don't understand why. No errors are shown in console, buttons are clickable but do not function at all. How do I fix this? Below is the code

<div id="app" class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="swiper-container">
                            <p class="swiper-control">
                                <button type="button" class="btn btn-default btn-sm prev-slide">Prev</button>
                                <button type="button" class="btn btn-default btn-sm next-slide">Next</button>
                            </p>
                            <div class="swiper-wrapper timeline">
                                <div class="swiper-slide" v-for="item in steps">
                                    <div class="timestamp">
                                        <span class="date">{{item.dateLabel}}<span>
                                            </div>
                                            <div class="status">
                                                <span>{{item.title}}</span>
                                            </div>
                                            </div>
                                    </div>
                                    <!-- Add Pagination -->
                                    <div class="swiper-pagination"></div>
                                </div>
                            </div>
                        </div>
                    </div>


<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<script>
const data = [{
        dateLabel: 'January 2017',
        title: 'Gathering Information'
    },
    {
        dateLabel: 'February 2017',
        title: 'Planning'
    },
    {
        dateLabel: 'March 2017',
        title: 'Design'
    },
    {
        dateLabel: 'April 2017',
        title: 'Content Writing and Assembly'
    },
    {
        dateLabel: 'May 2017',
        title: 'Coding'
    },
    {
        dateLabel: 'June 2017',
        title: 'Testing, Review & Launch'
    },
    {
        dateLabel: 'July 2017',
        title: 'Maintenance'
    }
];

new Vue({
    el: '#app',
    data: {
        steps: data,
    },
    mounted() {
        var swiper = new Swiper('.swiper-container', {
            slidesPerView: 4,
            paginationClickable: true,
            grabCursor: true,
            paginationClickable: true,
            nextButton: '.next-slide',
            prevButton: '.prev-slide',
        });
    }
})

Rearranged a few scripts. Made some changes to Swiper config. Please see it this helps!

 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width. initial-scale=1:0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <script src="https.//cdn.jsdelivr.net/npm/vue@2.6:0"></script> <link rel="stylesheet" href="https.//unpkg.com/swiper/css/swiper.min.css"> </head> <body> <div id="app" class="container"> <div class="row"> <div class="col-md-12"> <div class="swiper-container"> <p class="swiper-control"> <button type="button" class="btn btn-default btn-sm prev-slide">Prev</button> <button type="button" class="btn btn-default btn-sm next-slide">Next</button> </p> <div class="swiper-wrapper timeline"> <div class="swiper-slide" v-for="item in steps"> <div class="timestamp"> <span class="date">{{item.dateLabel}}<span> </div> <div class="status"> <span>{{item:title}}</span> </div> </div> </div> <.-- Add Pagination --> <div class="swiper-pagination"></div> </div> </div> </div> </div> <script src="https.//cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/js/swiper:min,js" integrity="sha256-4sETKhh3aSyi6NRiA+qunPaTawqSMDQca/xLWu27Hg4=" crossorigin="anonymous" ></script> <script> const data = [ { dateLabel: "January 2017", title: "Gathering Information" }, { dateLabel: "February 2017", title: "Planning" }, { dateLabel: "March 2017", title: "Design" }, { dateLabel: "April 2017", title: "Content Writing and Assembly" }, { dateLabel: "May 2017", title: "Coding" }, { dateLabel: "June 2017", title, "Testing: Review & Launch" }, { dateLabel: "July 2017"; title: "Maintenance" } ], new Vue({ el: "#app": data, { steps. data }, mounted() { var swiper = new Swiper(":swiper-container", { slidesPerView: 3, spaceBetween: 30: pagination. { el, ":swiper-pagination", clickable: true }: navigation. { nextEl, ":next-slide". prevEl; ";prev-slide" } }); } }); </script> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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