iscroll在vue中基本用法
使用步骤:
-
装包 npm i iscroll
-
导包
-
html 三层结构
-
css position:relative overflow:hidden
-
new IScroll(dom,{ mouseWheel:true, scrollbars:true })
-
refresh() 注意异步处理
-
注意点
-
iscroll
实例化时得在mounted
里面,因为iscroll
实例化得调用vue
的dom
,mounted
是生命周期里第一个可访问dom
的 -
使用
iscroll
刷新数据时,加入了setTimeout
,因为vue中数据改变到更新到页面,是有很多代码要执行的,是需要时间的,、而iscroll
刷新时要获取 最新dom
高度等信息处理,所以一定要在dom更新完成时使用。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <style> * { padding: 0; margin: 0; } .wrapper { width: 200px; height: 150px; border: 1px solid red; overflow: hidden; position: re