码迷,mamicode.com
首页 > 其他好文 > 详细

vue轮播插件vue-awesome-swiper

时间:2021-06-09 15:37:07      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ext   between   temp   bsp   return   als   元素   strong   dsl   

一、安装依赖

npm install vue-awesome-swiper --save

二、引入awesome-swiper

src/main.js修改

import Vue from ‘vue‘

import App from ‘./App‘
import router from ‘./router‘
import VueAwesomeSwiper from ‘vue-awesome-swiper‘
import ‘swiper/css/swiper.css‘
 
Vue.config.productionTip = false
 
/* eslint-disable no-new */
new Vue({
  el: ‘#app‘,
  router,
  components: { App },
  template: ‘<App/>‘
})
 
Vue.use(VueAwesomeSwiper)
 
界面代码:
<template>
    <div>
          <swiper :options="swiperOption">
            <swiper-slide></swiper-slide>
            <swiper-slide></swiper-slide>
            <!--以下看需要添加-->
            <div class="swiper-scrollbar"></div> //滚动条
            <div class="swiper-button-next"></div> //下一项
            <div class="swiper-button-prev"></div> //上一项
            <div class="swiper-pagination"></div> //标页码
          </swiper>
   </div>
</template>  
 
 
 
 
 
 
 
 
 
 
应用界面js代码
 
<script>
import { Swiper, SwiperSlide, directive } from ‘vue-awesome-swiper‘
import ‘swiper/css/swiper.css‘
export default {
  name: "index",
  components: {
    Swiper,
    SwiperSlide
  },
  directives: {
    swiper: directive
  },
  data () {
    return {
      swiperOption: {
        // 分页器配置
        pagination: {
          el: ‘.swiper-pagination‘,
          clickable: true
        },
        // 设定初始化时slide的索引
        initialSlide: 0,
        //Slides的滑动方向,可设置水平(horizontal)或垂直(vertical)
        direction: ‘horizontal‘,
        // 自动切换图配置
        autoplay: {
          delay: 5000,
          stopOnLastSlide: false,
          disableOnInteraction: true
        },
        // 箭头配置
        navigation: {
          nextEl: ‘.swiper-button-next‘,
          prevEl: ‘.swiper-button-prev‘,
        },
        // 环状轮播
        loop: true,
        slidesPerView: ‘auto‘,
        loopedSlides: 3,
        loopAdditionalSlides: 0,
        // 一个屏幕展示的数量
        slidesPerView: 1,
        // 间距
        // spaceBetween: 26,
        // 修改swiper自己或子元素时,自动初始化swiper
        observer: true,
        // 修改swiper的父元素时,自动初始化swiper
        observeParents: true
      }
    }
  }
}
</script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

vue轮播插件vue-awesome-swiper

标签:ext   between   temp   bsp   return   als   元素   strong   dsl   

原文地址:https://www.cnblogs.com/anna001/p/14866606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!