【问题标题】:Bootstrap carousel TypeError: $next[0] is undefined引导轮播类型错误:$next[0] 未定义
【发布时间】:2017-12-07 12:31:37
【问题描述】:

我使用 Vue2 在 Laravel 5.5 网站上构建了一个引导轮播。一切正常,但现在,突然之间,幻灯片无法正常滑动,控制台抛出以下 TypeError:

类型错误:$next[0] 未定义

向后滑动没问题,但是向右滑动时(即下一张幻灯片),轮播显示一些空白或直接跳到下一张幻灯片而不滑动。 我正在通过 CDN 导入引导程序。这是我的轮播的样子(包括 Vue 指令):

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            <figure v-for="(pic, index) in pics" :class="(pic_key === index) ? 'carousel-item active' : 'carousel-item'">
                <img class="d-block w-100" :src="pic" alt="">
            </figure>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>

这是我的 Vue 文件 (app.js):

require('./bootstrap');
window.Vue = require('vue');
window.filters = require('vue2-filters');
window.Event = new Vue();

Vue.component('location_map', require('./components/HomeMaps.vue'));

Vue.component('modal', {
    props: ['pic_key', 'pics', 'showGalleryModal'],
    template: `
        <div class="modal is-active">
            <div class="modal-background"></div>
            <div class="modal-content">
                <slot></slot>
            </div>
            <button class="modal-close is-large" aria-label="close" @click="$emit('close')"></button>
        </div>
    `
});

Vue.use(filters);

new Vue({
    el: '#root',
    data() {
        return {
            showGalleryModal: false,
            pic_key: 0,
            pics: [],
        }
    }
});

您可能已经注意到,在网站的另一个页面上还有另一个单个文件组件在做一些事情。在我实现了这个其他组件之后发生了错误,但我不明白为什么它会影响轮播,因为它与它无关(它甚至根本不使用引导程序)......

但是,有没有人知道如何解决这个问题?有没有可能这只是一个引导错误?

【问题讨论】:

    标签: javascript twitter-bootstrap carousel typeerror


    【解决方案1】:

    这只是发生在我身上。我意识到错误 $next[0] is undefined 被抛出是因为我使用的是 Bootstrap 3,而不是 4。

    使用 Bootstrap 3,包含图片的元素的类应该是 item 而不是 carousel-item

    所以,如果是你的情况,只需更改此行:

    <figure v-for="(pic, index) in pics" :class="(pic_key === index) ? 'carousel-item active' : 'carousel-item'">
    

    对此:

    <figure v-for="(pic, index) in pics" :class="(pic_key === index) ? 'item active' : 'item'">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 1970-01-01
      • 2014-04-10
      • 2017-01-25
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      相关资源
      最近更新 更多