在微信小程序中实现上下滑动翻页的效果其实非常简单,可以说一学就会。
这篇文章将非常详细地教大家如何实现这一交互:

数据准备
首先我们在 Page 的 data
属性中添加两个变量:
data: {
biases: [
{
"title": "Fundenmental Attribution Error",
"desc": "We judge others on their personality or fundamental character, but we judge ourselves on the situation.",
"ext": "Sally is late to class; she's lazy. You're late to class; it was a bad morning.",
"illustration": "biases/fundamental-attribution-error.jpg",
},
{
"title": "Self-Serving Bias",
"desc": "Our failures are situational, but our successes are our responsibility.",
"ext": "You won that award due to hard work rather than help or luck. Meanwhile, you failed a test because you hadn't gotten enough sleep.",
"illustration": "biases/self-serving-bias.jpg",
},
// ...
],
index: -1,
}
其中 biases
是个数组,我们要实现的效果就是每次展示 biases
的一个元素,上划切换到上一个元素,下划切换到下一个元素。
index
变量则用来表示当前元素的数组下标。
布局文件
数据准备完成之后,我们先来定义 wxml 文件:
<view class="page">
<swiper wx:if="{
{index >= 0}}"
class="swiper"
vertical<