vue使用原生swiper代码实例


Posted in Javascript onFebruary 05, 2020

这篇文章主要介绍了vue使用原生swiper代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

代码如下

<template>
  <div>
    <div class="swiper_Box" :class="identify">
      <div class="swiper-wrapper" :ref="identify">
        <div class="swiper-slide" v-for="(item,index) in imgArr" :key="'swiperSlide'+index">
          <div class="bannerItem">
            <img :src="item.url" alt="">
          </div>
        </div>
      </div>
      <!-- <div v-if="imgArr.length>1" class="swiper-button-prev" slot="button-prev"></div>
      <div v-if="imgArr.length>1" class="swiper-button-next" slot="button-next"></div> -->
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>

<script>
export default {
  props:['imgArr','identify','paginationType'],//接收传来的轮播图
  watch:{
    imgArr:{
      handler(newVal){
        console.log(newVal)
      },
      immediate:true
    },
    identify:{
      handler(newVal){
        console.log("id:"+newVal)
        var self=this;
      },
      immediate:true 
    }
  },
  data(){
    return{
      swiperShow:false,
      MySwiper:null,//swiper实例
    }
  },
  created(){
  },
  mounted(){
    var self=this;
    self.MySwiper = new Swiper ('.'+self.identify,{
      init: true,
      observer:true,
      observeParents:true,
      slidesPerView: 1,
      spaceBetween: 0,
      keyboard: {
        enabled: true,
      },
      loop: true,
      autoplay: {
        delay: 8000,
        disableOnInteraction: false
      },
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
        type:self.paginationType?self.paginationType:'bullets'
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev'
      },
    });
  }
}
</script>

<style scoped>
@import url("../styles/swiperBullet.css");
/* 轮播图 */
.swiperBox{
  width:100%;
}
.swiper_Box{
  position: relative;
  overflow: hidden;
}
.swiper_Box .bannerItem img{
  height:auto;
  width:100%;
}
.swiperBox .bannerItem{
  width:100%;
  text-align: center;
}
.swiperBox .bannerItem img{
  height:auto;
  width:100%;
}
.swiper-pagination{
  position: absolute;
  bottom:20px;
  left:50%;
  transform: translateX(-50%);
}

</style>

swiper的引入形式是link标签引入样式

script标签引入js

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
静态的动态续篇之来点XML
Aug 15 Javascript
再论Javascript下字符串连接的性能
Mar 05 Javascript
js动态添加事件并可传参数示例代码
Oct 21 Javascript
纯JS实现根据CSS的class选择DOM
Mar 22 Javascript
javascript实现模拟时钟的方法
May 13 Javascript
JavaScript+CSS实现仿天猫侧边网页菜单效果
Aug 25 Javascript
jQuery简单设置文本框回车事件的方法
Aug 01 Javascript
windows下vue.js开发环境搭建教程
Mar 20 Javascript
令按钮悬浮在(手机)页面底部的实现方法
May 02 Javascript
微信小程序页面生命周期详解
Jan 31 Javascript
Vue移动端用淘宝弹性布局lib-flexible插件做适配的方法
May 26 Javascript
10分钟学会js处理json的常用方法
Dec 06 Javascript
Vue如何使用混合Mixins和插件开发详解
Feb 05 #Javascript
JS原型和原型链原理与用法实例详解
Feb 05 #Javascript
js实现视图和数据双向绑定的方法分析
Feb 05 #Javascript
小程序如何写动态标签的实现方法
Feb 05 #Javascript
vue如何实现动态加载脚本
Feb 05 #Javascript
vue实现图片懒加载的方法分析
Feb 05 #Javascript
Vue组件基础用法详解
Feb 05 #Javascript
You might like
PHP动态创建Web站点的方法
2011/08/14 PHP
关于PHP二进制流 逐bit的低位在前算法(详解)
2013/06/13 PHP
PHP的PDO大对象(LOBs)
2019/01/27 PHP
PHP简单验证码功能机制实例详解
2019/03/27 PHP
javascript中删除指定数组中指定的元素的代码
2011/02/12 Javascript
使用原生javascript创建通用表单验证——更锋利的使用dom对象
2011/09/13 Javascript
到处都是jQuery选择器的年代 不了解它们的性能,行吗
2012/06/18 Javascript
JQuery中根据属性或属性值获得元素(6种情况获取方法)
2013/01/17 Javascript
JavaScript中的函数重载深入理解
2014/08/04 Javascript
jQuery构造函数init参数分析
2015/05/13 Javascript
require.js配合插件text.js实现最简单的单页应用程序
2016/07/12 Javascript
基于bootstrap实现收缩导航条
2017/03/17 Javascript
angularjs使用div模拟textarea文本框的方法
2018/10/02 Javascript
kafka调试中遇到Connection to node -1 could not be established. Broker may not be available.
2019/09/17 Javascript
关于vue2强制刷新,解决页面不会重新渲染的问题
2019/10/29 Javascript
node 版本切换的实现
2020/02/02 Javascript
Vue实现可移动水平时间轴
2020/06/29 Javascript
如何将Node.js中的回调转换为Promise
2020/11/10 Javascript
[01:35]2018年度CS GO最佳战队-完美盛典
2018/12/17 DOTA
python分割文件的常用方法
2014/11/01 Python
windows系统下Python环境的搭建(Aptana Studio)
2017/03/06 Python
python采集微信公众号文章
2018/12/20 Python
如何在Django中添加没有微秒的 DateTimeField 属性详解
2019/01/30 Python
python实现函数极小值
2019/07/10 Python
python3反转字符串的3种方法(小结)
2019/11/07 Python
Charles&Keith美国官方网站:新加坡快时尚鞋类和配饰零售商
2019/11/27 全球购物
安全检查管理制度
2014/02/02 职场文书
广告设计应届生求职信
2014/03/01 职场文书
教师考核材料
2014/05/21 职场文书
会计人员演讲稿
2014/09/11 职场文书
功夫熊猫观后感
2015/06/10 职场文书
礼仪培训心得体会
2016/01/22 职场文书
描述鲁迅的名言整理,一生受用
2019/08/08 职场文书
我对PyTorch dataloader里的shuffle=True的理解
2021/05/20 Python
关于的python五子棋的算法
2022/05/02 Python
MySQL 数据 data 基本操作
2022/05/04 MySQL