跨境派

跨境派

跨境派,专注跨境行业新闻资讯、跨境电商知识分享!

当前位置:首页 > 综合服务 > 物流仓储 > Swiper在Vue2中的使用

Swiper在Vue2中的使用

时间:2024-04-24 10:00:33 来源:网络cs 作者:晨起 栏目:物流仓储 阅读:

标签: 使用 

以swiper3为例

一、全局引入

1. 下载swiper3

cnpm install swiper@3 vue-awesome-swiper@3 --save-dev

 2. 在main.js中引入Vue-Awesome-Swiper

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

 3.  在swiper.vue中 

<template><div><swiper :options="swiperOption" ref="mySwiper"><swiper-slide>I'm Slide 1</swiper-slide><swiper-slide>I'm Slide 2</swiper-slide><swiper-slide>I'm Slide 3</swiper-slide><div class="swiper-pagination" slot="pagination"></div></swiper></div></template><script>export default {name: 'HomeSwiper',data () {return {swiperOption: {loop: true,autoplay: {delay: 3000,stopOnLastSlide: false,          disableOnInteraction: false},pagination: {el: '.swiper-pagination',                    type: 'fraction',clickable: true},}}}}</script><style lang="scss" scoped></style>

注意分页器的写法

2.6.7版本

swiperOption: {    loop: true,//可选选项,开启循环    autoplay: 5000,//可选选项,自动滑动pagination: '.swiper-pagination',paginationType: 'fraction',paginationClickable: true}

3.1.3版本

swiperOption: {    loop: true,autoplay: {delay: 3000,stopOnLastSlide: true, //当切换到最后一个slide时停止自动切换        disableOnInteraction: true //用户操作swiper之后,是否禁止autoplay},pagination: {el: '.swiper-pagination',type: 'fraction',        clickable: true}}

二、按需引入

1. 下载swiper3

cnpm install swiper@3 vue-awesome-swiper@3 --save-dev

 2.  在swiper.vue中 引入样式和组件

<template><div><swiper :options="swiperOption" ref="mySwiper"><swiper-slide>I'm Slide 1</swiper-slide><swiper-slide>I'm Slide 2</swiper-slide><swiper-slide>I'm Slide 3</swiper-slide><div class="swiper-pagination" slot="pagination"></div></swiper></div></template><script>import { swiper, swiperSlide } from "vue-awesome-swiper";import "swiper/dist/css/swiper.css";export default {name: 'HomeSwiper',components: {swiper,swiperSlide},data () {return {swiperOption: {loop: true,autoplay: {delay: 3000,stopOnLastSlide: false,          disableOnInteraction: false},pagination: {el: '.swiper-pagination',clickable: true}}}}}</script><style lang="scss" scoped></style>

loop: true失效问题

数据是写死的时候,能够loop:true是有效的;

数据是动态获取的loop:true就会失效。

解决办法:

加上v-if="list.length"有效解决

computed: {isShowSwiper () {return this.list.length}}

本文链接:https://www.kjpai.cn/news/2024-04-24/161704.html,文章来源:网络cs,作者:晨起,版权归作者所有,如需转载请注明来源和作者,否则将追究法律责任!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。

上一篇:curl 调用webservice请求

下一篇:返回列表

文章评论