我使用 Vue2 在 Laravel 5.5 网站上构建了一个 Bootstrap 轮播。一切工作正常,但现在突然之间,幻灯片无法正常滑动,并且控制台抛出以下 TypeError:
TypeError: $next[0] is undefined
向后滑动没问题,但向右滑动时(即下一张幻灯片),轮播显示一些空白或直接跳到下一张幻灯片而不滑动。 我正在通过 CDN 导入 bootstrap。这就是我的轮播的样子(包括 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: [],
}
}
});
您可能已经注意到,还有另一个单个文件组件在网站的另一个页面上执行一些操作。在我实现这个其他组件之后发生了错误,但我不明白为什么它会影响轮播,因为它与它无关(它甚至根本不使用 Bootstrap )...
但是,有人知道如何解决这个问题吗?这有可能只是一个 Bootstrap 错误吗?
最佳答案
这就是发生在我身上的事情。我意识到抛出错误 $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'">
关于javascript - Bootstrap轮播类型错误: $next[0] is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47695240/