Swiper 7在項目vue2中的引用


參考出坑https://blog.csdn.net/u012570307/article/details/107203851/

 

一、安裝

首先看看官網 https://www.swiper.com.cn/api/navigation/355.html

 

安裝

 

 

因為我本地安裝這樣是無效,版本也不太對

==============

所以我直接安裝

cnpm i swiper@7 vue-awesome-swiper@4 -S

 

二、案例實現

2.1 demo1 自動定時橫向滾動條

 

橫向滾動(不知道怎么放視頻,只能口說了)

代碼如下

 <swiper :options="swiperOption"
          class="companyJT__page-top">
    <swiper-slide class="companyJT__page-top__item">2西安豆粕成交價: 3800元/噸</swiper-slide>
    <swiper-slide class="companyJT__page-top__item">3聖迪樂村品牌蛋價格: 10元/公斤</swiper-slide>
    <swiper-slide class="companyJT__page-top__item">4聖迪樂村品牌蛋價格: 3800元/噸</swiper-slide>
    <swiper-slide class="companyJT__page-top__item">5西安豆粕成交價: 3800元/噸</swiper-slide>
    <swiper-slide class="companyJT__page-top__item">6聖迪樂村品牌蛋價格: 10元/公斤</swiper-slide>
    <swiper-slide class="companyJT__page-top__item">7聖迪樂村品牌蛋價格: 3800元/噸</swiper-slide>
  </swiper>

 

 1 <script>
 2 import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
 3 import Swiper2, { Autoplay } from 'swiper' // 自動滾動功能要單獨引入
 5 import 'swiper/swiper-bundle.css'
 8 
 9 Swiper2.use([Autoplay])
10 export default {
11   components: {
12     Swiper,
13     SwiperSlide
14   },
15   props: {
16     topData: {
17       type: Array,
18       default: () => []
19     }
20   },
21   data () {
22     return {
34       swiperOption: {
35         speed: 2000, // 切換速度
36         // 設定初始化時slide的索引
37         initialSlide: 0,
38         // Slides的滑動方向,可設置水平(horizontal)或垂直(vertical)
39         // direction: 'horizontal',
40         // 修改swiper自己或子元素時,自動初始化swiper
41         observer: true,
42         // 修改swiper的父元素時,自動初始化swiper
43         observeParents: true,
44         // 自動切換圖配置
45         autoplay: {
46           delay: 1000,
47           stopOnLastSlide: false,
48           disableOnInteraction: false
49         },
50         // 環狀輪播
51         loop: true,
52         slidesPerView: 3 // 一個屏幕展示的數量
53 
54       }
55     }
56   }
57 
58 }
59 </script>
 1 </script>
 2 
 3 <style lang="scss">
 4 .companyJT__page-top {
 5   position: relative;
 6   height: 100%;
 7   width: 54%;
 8   // margin: 0 20%;
 9   margin-top: px2rem(10);
10   margin-left: 24%;
11   overflow: hidden;
12   & > div:first-child {
13     // 解決水平滾動不生效的bug
14     display: flex !important;
15   }
16   &__item {
17     font-size: px2rem(16);
18     color: #fff;
19     // width: px2rem(324) !important;
20     height: px2rem(46);
21     line-height: px2rem(46);
22     background: url('../../assets/img/jtText_bg.png') no-repeat; // 本地的背景圖片
23     background-size: 100% 100%;
24     // margin-right: px2rem(10);
25     text-align: center;
26   }
27 }
28 </style>

 更多案例參考另一篇文案https://www.cnblogs.com/yflbk-2016/p/16194059.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM