当前位置:网站首页>uniapp的swiper动态设置current值不生效解决办法
uniapp的swiper动态设置current值不生效解决办法
2022-07-28 06:29:00 【1024小神】
当只是给了current值的时候,当你通过js重新设置为0时,不生效:
原因:current属性绑定的值(currentswiper)没有随着swiper的滑动而改变
解决办法:监听滑块change事件,手动给currentswiper赋值
需要加上@change事件,而且是必须加上才可以:
然后在change事件里设置:
changeswiper(e) {
this.currentImgIndex = e.detail.current
}
changeswiper方法是为了在swiper改变时实时的更新currentswiper 的值,如果不加这个方法手动滑动时currentswiper 不会随着滑动而改变会一直为0(初始值),因为currentswiper 值没有改变initcurrent 方法就不会生效swiper就不会回到第一个滑块
官方文档是这么说的
官方提供了两种解决办法(以swiper为例)
一:监听change事件,记录下当前的current的值this.old = e.detail.current ,在调用initcurrent方法重置滑块的时候先给currentswiper 赋值为old 的值,后再重置currentswiper 为0.
二:监听change事件,当current的值改变时把current的值赋给currentswiper ,然后再重置currentswiper 为0.(也就是上面的方法)

边栏推荐
- GD32使用ST的HAL库和GD官方库的一些体会
- 【17】 Establish data path (upper): instruction + operation =cpu
- 任务管理器中,显示的CPU速度大于它的最大速度【主频】
- Puzzle (004.3) pattern puzzle
- 百度智能云九州区县大脑,描绘城乡新蓝图!
- What if the computer file cannot be deleted?
- 【13】加法器:如何像搭乐高一样搭电路(上)?
- 豪华版h5俄罗斯方块小游戏源码
- Enum class
- Redis of non relational database [detailed setup of redis cluster]
猜你喜欢

Parse tree structure JS

03 | project deployment: how to quickly deploy a website developed based on the laravel framework

解决CNN固有缺陷!通用 CNN 架构CCNN来了| ICML2022

华为高级工程师---BGP路由过滤及社团属性

Basic dictionary of deep learning --- activation function, batch size, normalization

数字签名和CA证书

XSS知识点和20字符短域名绕过

What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
![[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial](/img/67/5373c45716ade5fbd1d3a980d8e5da.png)
[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial

Prescan quick start to master the track editing path of Lecture 16
随机推荐
Technology sharing | common proxy tools for interface testing
The even number of an integer queue is placed in the front, the odd number is placed in the back, and the relative position of the even and odd numbers remains unchanged
mysql:LIKE和REGEXP操作有什么区别?
js糖果消消乐小游戏源码
Enum class
华为高级工程师---BGP路由过滤及社团属性
基于单例模式的yaml参数配置
03 | 项目部署:如何快速部署一个基于laravel框架开发的网站
awk从入门到入土(16)awk变量类型探讨--关于数字和string两种类型
CarSim simulation quick start (10) - Modeling of braking system
Understanding of spark operator aggregatebykey
Opentsdb time series database
PostgreSQL is the world's most advanced open source relational database
(Reprinted) plantuml Quick Guide
Puzzle (004.3) pattern puzzle
Mechanical revolution Jiaolong P wired network card driver can't play
Prescan quick start to master the transportation elements in lesson 14, prescan
Change the dataDir path after mysql8.0.16 installation
CarSim simulation quick start (XI) - Driver Model (1)
我们如何在mysql中运行批处理模式?