bootstrap * slide.bs.carousel *事件未在vue js中触发

时间:2018-12-26 05:47:29

标签: jquery twitter-bootstrap vue.js carousel

<div id="appFeatureimg" class="carousel slide">
    <div class="carousel-inner row w-100 mx-auto">
        <div class="carousel-item col-md-3 col-sm-3 col-3"  :class= "{active: index==0 }" v-for="(screenshot,index) in app_details.screenshots">
            <div class="panel panel-default">
               <div class="panel-thumbnail">
                     <a href="#" class="thumb">
                          <img class="img-fluid mx-auto d-block" :src="screenshot"alt="slide 1" >
                     </a>
               </div>
           </div>
       </div>
   </div>
   <a class="carousel-control-prev" href="#appFeatureimg" 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 text-faded" href="#appFeatureimg" role="button" data-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
   </a>
</div>

这是我在其中生成轮播项目的html

 <script>
            vue js code goes here
 </script>

和其他js代码

<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script>
    $( document ).ready(() => {
        console.log('ready');
        $('#appFeatureimg').on('slide.bs.carousel', (e) => {
            console.log('ready2');
            var $e = $(e.relatedTarget);
            var idx = $e.index();
            var itemsPerSlide = 4;
            var totalItems = $('.carousel-item').length;

            if (idx >= totalItems-(itemsPerSlide-1)) {
                var it = itemsPerSlide - (totalItems - idx);
                for (var i=0; i<it; i++) {
                    // append slides to end
                    if (e.direction=="left") {
                        $('.carousel-item').eq(i).appendTo('.carousel-inner');
                    }
                    else {
                        $('.carousel-item').eq(0).appendTo('.carousel-inner');
                    }
                }
            }
        });
    });
</script>

这是我的轮播jQuery。

在执行document.ready函数之后,我得到了控制台打印,但引导事件 slide.bs.carousel 没有启动。 我把这些代码放在vue js和其他脚本之前,但是没有结果。 任何建议都是非常可取的。

1 个答案:

答案 0 :(得分:0)

移动

$( document ).ready(() => {
        console.log('ready');
        $('#appFeatureimg').on('slide.bs.carousel', (e) => {
            console.log('ready2');
            var $e = $(e.relatedTarget);
            var idx = $e.index();
            var itemsPerSlide = 4;
            var totalItems = $('.carousel-item').length;

            if (idx >= totalItems-(itemsPerSlide-1)) {
                var it = itemsPerSlide - (totalItems - idx);
                for (var i=0; i<it; i++) {
                    // append slides to end
                    if (e.direction=="left") {
                        $('.carousel-item').eq(i).appendTo('.carousel-inner');
                    }
                    else {
                        $('.carousel-item').eq(0).appendTo('.carousel-inner');
                    }
                }
            }
        });

到vue js组件的已安装部分