国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3中使用swiper(9)完整版

這篇具有很好參考價(jià)值的文章主要介紹了vue3中使用swiper(9)完整版。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

vue3中使用swiper(9)完整版

vue3中使用swiper(9)完整版

1、使用方式

1)安裝 swiper插件;

方法一:npm install swiper

方法二:yarn add swiper

注意:如果npm 無(wú)法安裝swiper時(shí),使用yarn安裝;

npm install -g yarn // 安裝yarn
yarn init # yarn  // 初始化
yarn remove 包名稱  // 刪除某個(gè)包
yarn run serve  // 運(yùn)行

vue3中使用swiper(9)完整版

2)參數(shù)介紹
  • modules:

  • loop: 是否循環(huán)播放

  • slides-per-view:控制一次顯示幾張輪播圖

  • space-between: 每張輪播圖之間的距離,該屬性不可以和margin 屬性同時(shí)使用;

  • autoplay: 是否自動(dòng)輪播, delay為間隔的毫秒數(shù);disableOnInteraction屬性默認(rèn)是true,也就是當(dāng)用戶手動(dòng)滑動(dòng)后禁用自動(dòng)播放, 設(shè)置為false后,將不會(huì)禁用,會(huì)每次手動(dòng)觸發(fā)后再重新啟動(dòng)自動(dòng)播放。

  • navigation: 定義左右切換箭頭

  • pagination: 控制是否可以點(diǎn)擊圓點(diǎn)指示器切換輪播

  • scrollbar: 是否顯示輪播圖的滾動(dòng)條, draggable設(shè)置為 true就可以拖動(dòng)底部的滾動(dòng)條(輪播當(dāng)中,一般不怎么會(huì)使用到這個(gè)屬性)

2、代碼如下

1)組件swiperCom.vue的代碼:

<template>
  <swiper
    class="swiper"
    :modules="modules"
    :loop="true"
    :slides-per-view="1"
    :space-between="50"
    :navigation="navigation"
    :autoplay="{ delay: 3000, disableOnInteraction: false }"
    :pagination="{ clickable: true }"
    :scrollbar="{ draggable: true }"
    @swiper="onSwiper"
    @slideChange="onSlideChange"
  >
    <swiper-slide
      v-for="(item, index) in imgs"
      :key="index"
      class="swiper-slide"
    >
      <img :src="item.pic" alt="" class="swiper-img" />
    </swiper-slide>
    <div class="swiper-button-prev" @click.stop="prevEl(item, index)" />
    <!--左箭頭。如果放置在swiper外面,需要自定義樣式。-->
    <div class="swiper-button-next" @click.stop="nextEl" />
    <!--右箭頭。如果放置在swiper外面,需要自定義樣式。-->
    <!-- 如果需要滾動(dòng)條 -->
    <!-- <div class="swiper-scrollbar"></div> -->
  </swiper>
</template>
<script>
// Import Swiper Vue.js components
import { ref } from 'vue'
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Autoplay, Navigation, Pagination, Scrollbar, A11y } from 'swiper'
import 'swiper/scss'
import 'swiper/scss/navigation'
import 'swiper/scss/pagination'
// import 'swiper/css/scrollbar'

export default {
  name: 'SwiperCom',
  data () {
    return {
      imgs: [
        { pic: require('../assets/001.jpg') },
        { pic: require('../assets/002.jpg') },
        { pic: require('../assets/003.jpg') },
        { pic: require('../assets/004.png') }
      ]
    }
  },
  components: {
    Swiper,
    SwiperSlide
  },
  setup () {
    const onSwiper = (swiper) => {
      console.log(swiper)
    }
    const navigation = ref({
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    })
    const prevEl = (item, index) => {
      // console.log('上一張' + index + item)
    }
    const nextEl = () => {
      // console.log('下一張')
    }
    // 更改當(dāng)前活動(dòng)swiper
    const onSlideChange = (swiper) => {
      // swiper是當(dāng)前輪播的對(duì)象,里面可以獲取到當(dāng)前swiper的所有信息,當(dāng)前索引是activeIndex
      console.log(swiper.activeIndex)
    }
    return {
      onSwiper,
      onSlideChange,
      prevEl,
      nextEl,
      navigation,
      modules: [Autoplay, Navigation, Pagination, Scrollbar, A11y]
    }
  }
}
</script>
<style lang="scss" > 
.swiper {
  width: 339rem;
  height: 150rem;
  background-color: antiquewhite;
  .swiper-slide {
    .swiper-img {
      width: 339px;
      height: 150px;
    }
  }
  .swiper-button-next,
  .swiper-button-prev {
    --swiper-theme-color: red;
    --swiper-navigation-size: 20rem;
  }
//   改變小圓點(diǎn)的樣式
  .swiper-pagination-bullet-active {
    background: white;
  }
}
</style>

vue3中使用swiper(9)完整版

2)組件HomeView.vue的代碼:

<template>
  <div class="home">
    <swiperCom />  // 在HomeView中調(diào)用組件swiperCom
  </div>
</template>

<script>
// @ is an alias to /src
import swiperCom from '@/components/swiperCom.vue' // 引入組件swiperCom
export default {
  name: 'HomeView',
  components: {
    swiperCom   // 所用到的組件記得寫在components中
  }
}
</script>

3、基本步驟

1)在 components 文件中新建組件 swiperCom.vue ,在HomeView.vue中調(diào)用組件

vue3中使用swiper(9)完整版文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-492328.html

到了這里,關(guān)于vue3中使用swiper(9)完整版的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue3.0 透?jìng)鲗傩院褪录氖褂梅绞? decoding=
  • vue3中使用route、router、store的方式

    route: ?(1) vue3寫法: ?(2) vue2寫法: ?router: ?(1) vue3寫法: ?(2) vue2寫法: ?store: ?(1) vue3寫法: ?(2) vue2寫法:

    2024年02月13日
    瀏覽(45)
  • Vue3使用全局函數(shù)或變量的兩種常用方式

    例如:想要在index.ts中創(chuàng)建getAction函數(shù),并可以全局使用: 方式一:使用依賴注入(provide/inject) 在main.ts中進(jìn)行掛載: 在要使用的頁(yè)面注入: 方式二:使用 app.config.globalProperties 和 getCurrentInstance() app.config.globalProperties:一個(gè)用于注冊(cè)能夠被應(yīng)用內(nèi)所有組件實(shí)例訪問(wèn)到的全局

    2024年02月12日
    瀏覽(16)
  • 你可能從未使用過(guò)的調(diào)試 Vue3 (開源項(xiàng)目) 源碼的方式

    你可能從未使用過(guò)的調(diào)試 Vue3 (開源項(xiàng)目) 源碼的方式

    ????1. 前言 大家好,我是若川。我傾力持續(xù)組織了一年多源碼共讀,感興趣的可以加我微信 lxchuan12 參與。另外,想學(xué)源碼,極力推薦關(guān)注我寫的專欄《學(xué)習(xí)源碼整體架構(gòu)系列》,目前是掘金關(guān)注人數(shù)(4.7k+人)第一的專欄,寫有20余篇源碼文章。 看一個(gè)開源倉(cāng)庫(kù),第一步一

    2024年02月04日
    瀏覽(17)
  • vue中swiper使用

    說(shuō)明:導(dǎo)入相應(yīng)js引css import \\\"Swiper\\\" from \\\"swiper\\\" import \\\"swiper/css/swiper.css\\\"; import \\\"swiper/js/swiper\\\"; 說(shuō)明:必要的結(jié)構(gòu)使用;直接封裝成一個(gè)組件? 說(shuō)明:(頁(yè)面當(dāng)中務(wù)必要有結(jié)構(gòu));注釋已經(jīng)寫入代碼。 第一:可以解決獲取數(shù)據(jù)在Swiper實(shí)例之前;第二:可以解決v-for遍歷完后在Swiper之

    2024年02月14日
    瀏覽(20)
  • vue2 使用swiper

    vue2 使用swiper

    在vue2項(xiàng)目中要用到輪播的功能,用swiper插件實(shí)現(xiàn)遇到了一些坑 總結(jié)下。 一、運(yùn)行安裝命令: 如果直接運(yùn)行npm i swiper 是默認(rèn)安裝的最新版本是適用vue3 不適用vue2的 安裝完成后oackage.json多了 ?vue-awesome-swiper本來(lái)是5.0.1 我手動(dòng)改成了4.1.1,因?yàn)楫?dāng)我運(yùn)行時(shí),我的項(xiàng)目報(bào)錯(cuò) ?所以

    2024年02月11日
    瀏覽(27)
  • vue中swiper輪播圖的使用

    說(shuō)明:導(dǎo)入相應(yīng)js引css import \\\"Swiper\\\" from \\\"swiper\\\" import \\\"swiper/css/swiper.css\\\"; import \\\"swiper/js/swiper\\\"; 說(shuō)明:必要的結(jié)構(gòu)使用;直接封裝成一個(gè)組件? 說(shuō)明:(頁(yè)面當(dāng)中務(wù)必要有結(jié)構(gòu));注釋已經(jīng)寫入代碼。 第一:可以解決獲取數(shù)據(jù)在Swiper實(shí)例之前;第二:可以解決v-for遍歷完后在Swiper之

    2024年02月14日
    瀏覽(27)
  • vue使用swiper三行輪播問(wèn)題

    vue使用swiper三行輪播問(wèn)題

    1、輪播圖設(shè)置屬性slidesPerColumn:3實(shí)現(xiàn)不了,解決方案如下: this.scheduleData是后臺(tái)請(qǐng)求的數(shù)據(jù),通過(guò)3個(gè)一組分組轉(zhuǎn)換為this.scheduleListThreede 的數(shù)據(jù)! 2、邏輯處理如下: computed: { ? ? ? scheduleListThree: function () { ? ? ? ? ? let index = 0; ? ? ? ? ? let count = 3; ? ? ? ? ? let arrThree

    2024年02月09日
    瀏覽(21)
  • Swiper在Vue2中的使用

    以swiper3為例 1. 下載swiper3 ?2.?在main.js中引入Vue-Awesome-Swiper ?3.? 在swiper.vue中? 2.6.7版本 3.1.3版本 1. 下載swiper3 ?2.? 在swiper.vue中?引入樣式和組件 數(shù)據(jù)是寫死的時(shí)候,能夠loop:true是有效的; 數(shù)據(jù)是動(dòng)態(tài)獲取的loop:true就會(huì)失效。 解決辦法: 加上v-if=\\\"list.length\\\"有效解決

    2024年02月11日
    瀏覽(24)
  • vue3:router安裝與使用

    vue3:router安裝與使用

    Terminal中運(yùn)行以下代碼自動(dòng)安裝 安裝完成后,在package.json中查看vue-router是否安裝成功 src目錄下新建一個(gè)router文件夾,在router文件夾里新建一個(gè)index.js文件,index.js中的代碼如下 main.js中代碼如下 在主頁(yè)面App.vue中的模板內(nèi)寫入一下兩行代碼即可 運(yùn)行項(xiàng)目,打開運(yùn)行地址,此時(shí)

    2023年04月19日
    瀏覽(15)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包