• Vue 之 插件 轮播组件 vue-awesome-swiper 的简单使用整理


    Vue 之 插件 轮播组件 vue-awesome-swiper 的简单使用整理

    目录

    Vue 之 插件 轮播组件 vue-awesome-swiper 的简单使用整理

    一、简单介绍

    二、安装 vue-awesome-swiper

    三、引入(全局或局部引入)

    四、简单使用


    一、简单介绍

    Vue 开发的一些知识整理,方便后期遇到类似的问题,能够及时查阅使用。

    本节介绍,Vue 的轮播插件 vue-awesome-swiper ,并简单的使用,如果有不足之处,欢迎指出,或者你有更好的方法,欢迎留言。

    vue-awesome-swiper 是第一个第三方的库,可以用来实现移动端、pc端的滑动操作,十分方便。

    网址:GitHub - surmon-china/vue-awesome-swiper: 🏆 Swiper component for @vuejs

    Swiper(Swiper master)是目前应用较广泛的移动端网页触摸内容滑动js插件,是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端;能实现触屏焦点图、触屏Tab切换、触屏多图切换等常用效果

    值得注意的是:目前 vue-awesome-swiper@3.1.3 版本最为稳定,其他版本可能不太稳定,建议优先使用 vue-awesome-swiper@3.1.3

    二、安装 vue-awesome-swiper

    使用 npm install vue-awesome-swiper@3.1.3 -S 进行安装

    三、引入(全局或局部引入)

    1、全局引入

    1. import Vue from 'vue'
    2. // 引入 vue-awesome-swiper
    3. import VueAwesomeSwiper from 'vue-awesome-swiper'
    4. //引入 vue-awesome-swiper 样式
    5. import 'swiper/css/swiper.css'
    6. Vue.use(VueAwesomeSwiper, /* { 全局组件的默认选项 } */)

    2、局部引入

    四、简单使用

    1、首先创建工程

    2、安装  vue-awesome-swiper

    3、创建一个 vue,局部引入 vue-awesome-swiper,实现自动轮播图片的功能,图片可点击

    1. <template>
    2. <div class="container">
    3. <swiper :options="mySwiperOption">
    4. <swiper-slide v-for=" i in 3" :key="i">
    5. <img :src="httpImageUrl" width="100%" @click="onClick(i)"/>
    6. swiper-slide>
    7. <div class="swiper-pagination" slot="pagination">div>
    8. swiper>
    9. div>
    10. template>
    11. <script>
    12. // 局部引入 vue-awesome-swiper 及其样式
    13. import {
    14. swiper,
    15. swiperSlide
    16. } from 'vue-awesome-swiper'
    17. import 'swiper/dist/css/swiper.css'
    18. export default {
    19. name: 'MyTestVueAwesomeSwipe',
    20. components: {
    21. // 注册 vue-awesome-swiper 组件
    22. swiper,
    23. swiperSlide
    24. },
    25. data() {
    26. return {
    27. mySwiperOption: {
    28. pagination: {
    29. el: '.swiper-pagination', //与slot="pagination"处 class 一致
    30. clickable: true, //轮播按钮支持点击
    31. },
    32. //自动播放
    33. autoplay: {
    34. delay: 1000,
    35. disableOnInteraction: false
    36. },
    37. //循环
    38. loop:true
    39. },
    40. httpImageUrl: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F013fe45544a15e0000019ae9049657.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1663827624&t=884f3f882f3070c1168c89864ae1c289"
    41. }
    42. },
    43. methods:{
    44. onClick(i){
    45. alert(i)
    46. }
    47. }
    48. }
    49. script>
    50. <style lang="scss" scoped>
    51. style>

    4、运行工程,效果如下

     

     

  • 相关阅读:
    Mysql数据库基础:DML数据操作语言
    IDEA 连接 数据库
    Towards End-to-End Unified Scene Text Detection and Layout Analysis(2022)
    React-3 组件知识
    3.Redis的5种数据结构
    软件测试-BUG
    必须要会回答的Java面试题(字符串篇)
    Spring声明式事务
    modern C++:闭包与匿名函数
    理解浅拷贝和深拷贝以及实现方法
  • 原文地址:https://blog.csdn.net/u014361280/article/details/126483457