国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

如何在VUE中使用vue-awesome-swiper

瀏覽:5日期:2022-10-12 18:12:51
一:首先進(jìn)入項(xiàng)目目錄中安裝

install vue-awesome-swiper@2.6.7 --save二.使用

全局掛載:

import Vue from ’vue’import VueAwesomeSwiper from ’vue-awesome-swiper’// require stylesimport ’swiper/dist/css/swiper.css’Vue.use(VueAwesomeSwiper, /* { default global options } */)

組件掛載

// require stylesimport ’swiper/dist/css/swiper.css’import { swiper, swiperSlide } from ’vue-awesome-swiper’export default { components: { swiper, swiperSlide }}

新建一個(gè).vue文件,按照以下代碼模式

<template> <div class='index'> <Top navLeft='true' navRight='false'></Top> <div style='padding-top: 1.3rem;padding-left:0.2rem'> <swiper :options='swiperOption' ref='mySwiper' v-if='swiperList.length!=0'> <swiper-slide v-for=’(item,index) of swiperList’ :key=’item.id’ > <img class=’swiper-img’ :src=’item.imgUrl’ alt='門票' @click='swiperClick(index,item.linkUrl)' /> </swiper-slide> <div slot='pagination'></div> </swiper> </div> </div></template><script>import Top from ’@/components/public/Top’;import ’swiper/dist/css/swiper.css’;import { swiper, swiperSlide } from ’vue-awesome-swiper’export default { name: ’Swiper’, components: {Top,swiper,swiperSlide}, data() { return { swiperList:[], swiperOption: { pagination: '.swiper-pagination', initialSlide: 0,//默認(rèn)第幾張 loop:true, //循環(huán) autoplayDisableOnInteraction:false,//觸摸后再次自動(dòng)輪播 autoplay:2000, //每張播放時(shí)長3秒,自動(dòng)播放 speed:1000,//滑動(dòng)速度 } } }, created(){ this.initEvent(); console.log(this.$refs.mySwiper); this.swiperOption.autoplay = this.swiperList.length != 1 ? 2000 : false;//如果是一張圖片不輪播 }, computed: { swiper() { return this.$refs.mySwiper.swiper//組件實(shí)例 } }, mounted(){ }, methods: { initEvent:function(){ this.$http.get('http://localhost/swiper') .then(res=>{ this.swiperList=res.data.swiperList; }) .catch(error=>{ console.log(error) }) }, swiperClick:function(index,url){ console.log(index); this.$router.push(url) } }}</script><style scoped>@import '../assets/public/css/bottom.css';@import '../assets/css/index/my.css';#mySwiper >>> .swiper-pagination-bullet { background: #000000;}#mySwiper >>> .swiper-pagination-bullet-active { background: #ff0000;}</style>

頁面展示如下

如何在VUE中使用vue-awesome-swiper

三:在使用過程中遇到的問題

1.觸摸后再次自動(dòng)輪播問題,添加以下屬性就可以再次輪播

autoplayDisableOnInteraction:false

2.樣式穿透問題,修改圓點(diǎn)的樣式問題

解決方案是給swiper容器添加上ID,然后再在后面添加>>>,這樣就可以解決了

#mySwiper >>> .swiper-pagination-bullet { background: #000000;}#mySwiper >>> .swiper-pagination-bullet-active { background: #ff0000;}

3.解決如果只有一張圖片不輪播問題

以上就是如何在VUE中使用vue-awesome-swiper的詳細(xì)內(nèi)容,更多關(guān)于VUE中使用vue-awesome-swiper的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 新兴县| 龙泉市| 青田县| 瑞昌市| 资兴市| 孙吴县| 凤庆县| 施甸县| 锡林浩特市| 佛学| 尖扎县| 饶阳县| 拉孜县| 左贡县| 浠水县| 定襄县| 丹凤县| 茌平县| 天镇县| 米林县| 镇原县| 天柱县| 平湖市| 千阳县| 杭锦后旗| 宽甸| 论坛| 寿宁县| 延长县| 百色市| 三河市| 册亨县| 昌乐县| 灌南县| 大港区| 阿克苏市| 新宾| 涿州市| 枣阳市| 琼结县| 平利县|