当前位置: 首页 > news >正文

vue中swiper使用

1.引包

说明:导入相应js引css

import "Swiper" from "swiper"

import "swiper/css/swiper.css";

import "swiper/js/swiper";

 2.结构

说明:必要的结构使用;直接封装成一个组件 

<template><div class="swiper-container" ref="cur"><div class="swiper-wrapper"><divclass="swiper-slide"v-for="carousel in list":key="carousel.id"><img :src="carousel.imgUrl" /></div></div><!-- 如果需要分页器 --><div class="swiper-pagination"></div><!-- 如果需要导航按钮 --><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>
</template>

3.new Swiper实例 

说明:(页面当中务必要有结构);注释已经写入代码。

第一:可以解决获取数据在Swiper实例之前;第二:可以解决v-for遍历完后在Swiper之前。

import Swiper from "swiper";
export default {name: "Carousel",props: ["list"],// 这样做的目的是在list属性发生变化时,// 能够及时更新Swiper轮播组件,以保证轮播的内容和效果与list属性的变化保持同步。watch: {list: {immediate: true,handler(newValue, oldValue) {// 这里有了数据还是不行,v-for有没有渲染也是问题,不能保证结构是否完成。// 用于在DOM更新后执行回调函数。在Vue中,当对数据进行修改后,DOM并不会立即更新,而是在下一个"tick"时进行更新。// 这个"tick"是Vue内部的更新队列,在执行用户逻辑之前进行DOM更新。this.$nextTick(function () {const mySwiper = new Swiper(this.$refs.cur, {loop: true,slidesPerView: "auto",slidesPerGroupAuto: true,autoplay: true,//如果需要分页器pagination: {el: ".swiper-pagination",clickable: true,//如果需要前进后退按钮navigation: {nextEl: ".swiper-button-next",prevEl: ".swiper-button-prev",},},});});},},},
};

http://www.lryc.cn/news/112292.html

相关文章:

  • webpack与vite区别
  • GLSL用于图像处理
  • 即将发布的 Kibana 版本可运行 Node.js 18
  • 基于遗传算法改进的支持向量机多分类仿真,基于GA-SVM的多分类预测,支持相机的详细原理
  • MySQL5.7源码编译Debug版本
  • ORA-48913: Writing into trace file failed, file size limit [50000000] reached
  • 线上Zookeeper问题解决记录
  • Docker极速安装Jenkins
  • TransnormerLLM 中 FlashLinearAttention 的纯pytorch实现
  • 从NPM注册中心获取包
  • Elastic的下载
  • day52-Redis
  • 高效处理矢量大数据的高可用解决方案
  • Docker Compose构建lnmp
  • Flutter开发问题记录
  • 如何使用本地mock数据
  • XXL-JOB定时任务框架(Oracle定制版)
  • SpringBoot + ajax 实现分页和增删查改
  • ProxyGenerator-代理类生成器
  • ARM 内存屏障指令
  • 了解Linux 的 mmap --- 笔记
  • docker删除容器(步骤详解)
  • boost beast http server 测试
  • Android 10.0 系统开启禁用adb push和adb pull传输文件功能
  • 浙大数据结构第七周之07-图4 哈利·波特的考试
  • vue2-vue项目中你是如何解决跨域的?
  • 【Paper Reading】DETR:End-to-End Object Detection with Transformers
  • 【rust/入门】windows安装rust gnu环境(折腾)
  • java面试---字符串相关内容
  • MYSQL进阶-事务的基础知识