当前位置: 首页 > 编程笔记 >

vue 中swiper的使用教程

公冶昆杰
2023-03-14
本文向大家介绍vue 中swiper的使用教程,包括了vue 中swiper的使用教程的使用技巧和注意事项,需要的朋友参考一下

Install

在vue cli下的使用

npm

install vue-awesome-swiper --save

在main.js

import  VueAwesomeSwiper from 'vue-awesome-swiper'
import  'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)

在component.vue中

<template>
<div id="container">
 <swiper :options="swiperOption" ref="mySwiper">
  <swiper-slide class="swiper-slide games">
   <img src="/src/assets/LB/LB_07.jpg" alt="">
  </swiper-slide>
  <swiper-slide class="swiper-slide games">
   <img src="/src/assets/LB/LB_06.jpg" alt="">
  </swiper-slide>
  <swiper-slide class="swiper-slide games">
   <img src="/src/assets/LB/LB_05.jpg" alt="">
  </swiper-slide>
  <swiper-slide class="swiper-slide games">
   <img src="/src/assets/LB/LB_04.jpg" alt="">
  </swiper-slide>
  <div class="swiper-pagination" slot="pagination"></div>
  <div class="swiper-button-prev" slot="button-prev"></div>
  <div class="swiper-button-next" slot="button-next"></div>
 </swiper>   
 </div> 
 </template>
<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
 export default {
  name: 'carrousel',
  data () {
   return {
    swiperOption: {
        autoplay : {
      disableOnInteraction: false, //用户操作后是否禁止自动循环
      delay: 3000 //自自动循环时间
     }, //可选选项,自动滑动
     speed: 2000, //切换速度,即slider自动滑动开始到结束的时间(单位ms)
     loop:true, //循环切换
     grabCursor: true, //设置为true时,鼠标覆盖Swiper时指针会变成手掌形状,拖动时指针会变成抓手形状
     // setWrapperSize: true, //Swiper使用flexbox布局(display: flex),开启这个设定会在Wrapper上添加等于slides相加的宽或高,在对flexbox布局的支持不是很好的浏览器中可能需要用到。
     autoHeight: true,   //自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化。   
     scrollbar: '.swiper-scrollbar',
     mousewheelControl: true, //设置为true时,能使用鼠标滚轮控制slide滑动
     observeParents: true, //当改变swiper的样式(例如隐藏/显示)或者修改swiper的子元素时,自动初始化swiper

     pagination: {
      el: '.swiper-pagination',
      // type : 'progressbar', //分页器形状
      clickable :true, //点击分页器的指示点分页器会控制Swiper切换
     },
     navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
     },       
   },
   computed: {
    swiper() {
     return this.$refs.mySwiper.swiper
    }
   }
  }
 }
}
</script>
<style scoped>
img {
 width: 100%;
 height: auto;
}
</style>

参考:https://github.com/surmon-china/vue-awesome-swiper

https://surmon-china.github.io/vue-awesome-swiper/

总结

以上所述是小编给大家介绍的vue 中swiper的使用教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对小牛知识库网站的支持!

 类似资料:
  • 本文向大家介绍解决vue中使用swiper插件问题及swiper在vue中的用法,包括了解决vue中使用swiper插件问题及swiper在vue中的用法的使用技巧和注意事项,需要的朋友参考一下 Swiper简介 Swiper常用于移动端网站的内容触摸滑动。 Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。 Swiper能实现触屏焦点图、触屏Tab切换、触屏多

  • 安装 import { Swiper } from 'vux' export default { components: { Swiper } } // 在入口文件全局引入 import Vue from 'vue' import { Swiper } from 'vux' Vue.component('swiper', Swiper) list为图片列表快捷设置,如果你需

  • 本文向大家介绍Vue框架里使用Swiper的方法示例,包括了Vue框架里使用Swiper的方法示例的使用技巧和注意事项,需要的朋友参考一下 下载swiper 首先使用npm 或者cnpm下载swiper 引入swiper 使用swiper mounted里面调用 注意 如果想要从后台请求图片放上去 new Swiper要写在网络请求成功的函数里面,否则不会出来数据。 slider组件的内容如下:

  • 本文向大家介绍animate.css在vue项目中的使用教程,包括了animate.css在vue项目中的使用教程的使用技巧和注意事项,需要的朋友参考一下 在vue项目中使用动画其实有多种方式,可以使用vue中的过渡transition,可以使用animate动画与transition配合使用,也可以单独使用animate动画库(详情可见vue官网-过渡:过渡),下面我们开始介绍在vue中单独使用

  • 本文向大家介绍vue中的router-view组件的使用教程,包括了vue中的router-view组件的使用教程的使用技巧和注意事项,需要的朋友参考一下 开发的时候有时候会遇到比如 点击这个链接跳转到其他组件的情况,氮素,我们不想跳转到新页面,只在当前页面切换着显示,那么就要涉及到路由的嵌套了,也可以说是子路由的使用。 比如我们在一个导航组件中写了三个导航链接,他们的地址分别为:/food,/r

  • 本文向大家介绍详解swiper在vue中的应用(以3.0为例),包括了详解swiper在vue中的应用(以3.0为例)的使用技巧和注意事项,需要的朋友参考一下 一、使用方法 官网地址 参考此文章(点击我) 二、常见情况 图片需要动态获取时 待数据加载成功且渲染完毕后,进行节点初始化。例: 当有 3 组图片需要依次播放时(多组以此类推) 情景:第 2 组图片滑动最后一张时,需要加载第 3 组图片;第