微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我正在尝试将 Vue 数据实现到 Bootstrap 轮播中

如何解决我正在尝试将 Vue 数据实现到 Bootstrap 轮播中

第一张幻灯片效果很好,但第二张幻灯片不会将 Vue 数据加载到幻灯片中。我不能使用 Vue slick carousel 或数组函数,因为 carousel 有很多对象。如果我尝试在数据中将它们分成自己的部分,它也会中断。我在下面包含了我的代码。我没有想法,可以使用你的。

''' <!DOCTYPE html>
<html lang="en" id="books_pg">
<head>
    <Meta charset="UTF-8">
    <title>Books</title>
    <Meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Fredericka+the+Great&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    <link rel="stylesheet" href="styles/main_boot.css">

</head>
<body>
<div id="container">
    <span id="header"></span>

    <main>
        <div class=" container">
            <div class="row"></div>
            <div id="bookSeries" class="carousel slide" data-interval="0" data-ride="carousel">
                <div  class="carousel-inner">
                    <div class="carousel-item active timeBooks" >
                        <div v-html="t105.bkCover" class="row"></div>
                        <div class="row">
                            <div class="container d-flex">
                                <div class="wrapper row ml-15 justify-content-center">
                                    <a class="trailer col-sm-12 col-md-2" :href="t105.link"><h2 class="text-bottom">trailer</h2></a>
                                    <p class="sum col-md-7">{{t105.sum}}</p>
                                    <a  class="meme col-sm-12 col-md-2" href="meme.html"> <h2>memes</h2></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="carousel-item timeBooks">
                        <div v-html="t205.bkCover" class="row"></div>
                        <div class="row">
                            <div class="container d-flex">
                                <div class="wrapper row ml-15 justify-content-center">
                                    <a class="trailer col-sm-12 col-md-2" :href="t205.link"><h2 class="text-bottom">trailer</h2></a>
                                    <p class="sum col-md-7">{{t205.sum}}</p>
                                    <a  class="meme col-sm-12 col-md-2" href="meme.html"> <h2>memes</h2></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div>
                    <a class="controller carousel-control-prev" href="#bookSeries" role="button" data-slide="prev">
                        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                    </a>
                    <a class="controller carousel-control-next" href="#bookSeries" role="button" data-slide="next">
                        <span class="carousel-control-next-icon" aria-hidden="true"></span>
                    </a>
                </div>
            </div>
        </div>
    </main>
    <div class="row justify-items-center">
        <a><h6 id="off">Off the Rails books</h6></a>
    </div>

    <div class="container">

        <div class="includes row">
            <span id="ft"></span>
        </div>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
<script src="app.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
        integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
        crossorigin="anonymous"></script>
<script src="jquery.js"></script>

</body>
</html>'''

'''const Test = new Vue({
    el: '.timeBooks',data: {
        t105: {
            bkCover:
                '<img class="cover d-block col-md-2 mx-auto mt-2 img-fluid" src="img/books/time105am.png" alt="1:05 A.M. cover">',sum: "At the beginning of a new ice era,past and present will collide,and love will survive the ice and sNow that encases the planet.\n" +
                "                                        Karmen-Marie has spent the last decade working for her father’s shady business as an assassin. Once underground she must hunt and kill her mysterIoUs target.\n" +
                "                                        Rea,a second-generation military trained instructor. Build,train,and move on,is the only way of life Rea understands.\n" +
                "                                        Rea’s former flame has come to kill him. An accidental mix-up causes the killer to loses her memory. Rae struggles to let this attractive hired gun back into his heart.",link: 'https://www.youtube.com/watch?v=UTgiOKYp-9s&feature=youtu.be',meme: '\meme.html',},t205: {
            bkCover:
                '<img class="cover d-block col-md-2 mx-auto mt-2 img-fluid" src="img/books/time205am.jpg" alt="2:05 A.M. cover">',sum: "class=\"sum col-sm-12 col-md-8 mr-3\"> After spending all her life trying to be normal,Nova gives up. Content in her private world and with no desire to change,she finds herself pulled into a mission that takes her away from her safe and secluded life.\n" +
                "                        Arrow has been trapped in a cage for,well,he can’t recall,but he is ready to be free. When his “Angel” appears,she’s what he’s been searching for all his life,and his soul kNows her. But his angel doesn’t kNow who he is,nor does she care,and she resists helping him.\n" +
                "                        Before long they will uncover the dark past that haunts Arrow,and the even darker future that awaits them both.",link: 'https://www.youtube.com/watch?v=ug2VqdaFmZY',}
})''''''

解决方法

我已经使用 Bootstrap 构建了几个 Vue 2 应用程序,但没有使用过 Carousel,所以这听起来像是一个有趣的练习。

我有一个用于测试功能的 Vue CLI 沙盒应用程序,因此我根据上面的代码创建了一个单一文件组件,开始编辑和构建,但最终决定从一个更简单的组件开始。我从文档中的 Bootstrap Carousel 示例创建了一个 SFC。我建议您简化代码,直到轮播也能正常工作。

一旦我确定在我的 main.js 中导入了 Bootstrap 和 jQuery(再次使用 Vue CLI),简化的轮播就可以工作了。这是我的 Carousel.vue 组件中的代码。我可能会做一些额外的工作来为轮播项目实现一个“v-for”循环,但想发布这个。

<template>
  <div class="row">
    <div class="col-md-6">
      <div class="carousel">
        <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
          <div class="carousel-inner">
            <div class="carousel-item active">
              <h4>{{ slideData[0].title }}</h4>
              <img class="d-block w-100" :src="slideData[0].imgSrc" :alt="slideData[0].title">
              <p>{{ slideData[0].text }}</p>
            </div>
            <div class="carousel-item">
              <h4>{{ slideData[1].title }}</h4>
              <img class="d-block w-100" :src="slideData[1].imgSrc" :alt="slideData[1].title">
              <p>{{ slideData[1].text }}</p>
            </div>
            <div class="carousel-item">
              <h4>{{ slideData[2].title }}</h4>
              <img class="d-block w-100" :src="slideData[2].imgSrc" :alt="slideData[2].title">
              <p>{{ slideData[2].text }}</p>
            </div>
          </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>
      </div>
  </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        slideData: [
          {
            id: 1,title: 'First slide',text: `The carousel is a slideshow for cycling through a series of content,built with CSS 3D transforms and a bit of JavaScript. It works with a series of images,text,or custom markup. It also includes support for previous/next controls and indicators.`,imgSrc: require('../../assets/images/my-portrait.jpg')
          },{
            id: 2,title: 'Second slide',text: `In browsers where the Page Visibility API is supported,the carousel will avoid sliding
             when the webpage is not visible to the user (such as when the browser tab is inactive,the browser
              window is minimized,etc.).`,{
            id: 3,title: 'Third slide',text: `Please be aware that nested carousels are not supported,and carousels are generally not
             compliant with accessibility standards.`,imgSrc: require('../../assets/images/my-portrait.jpg')
          }
        ]

      }
    }
  }
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。