picker

picker v0.9+

Updated time: 22/06/2017

概述

以下为 picker 相关的 API,用于数据选择,日期选择,时间选择。( H5模块如需使用,请手动引入weex-picker组件)

API

pick(options, callback[options])
调用单选 picker

参数

  • options {Object}:调用单选 picker 选项

    • index {number}:默认选中的选项
    • items {array}:picker 数据源
  • callback {function (ret)}:执行完读取操作后的回调函数。ret {Object}callback 函数的参数,有两个属性:

    • result {string}:结果三种类型 success, cancel, error
    • data {number}:选择的选项,仅成功确认时候存在。

pickDate(options, callback[options])
调用 date picker

参数

  • options {Object}:调用 date picker 选项

    • value {string}:必选,date picker 选中的值,date 的字符串格式为yyyy-MM-dd
    • max {string}:可选,date 的最大值
    • min {string}:可选,date 的最小值
  • callback {function (ret)}:执行完读取操作后的回调函数。ret {Object}callback 函数的参数,有两个属性:

    • result {string}:结果三种类型 success, cancel, error
    • data {string}:选择的值 date 的字符,格式为 yyyy-MM-dd, 仅成功确认的时候存在。

pickTime(options, callback[options])
调用 time picker

参数

  • options {Object}:调用 time picker 选项

    • value {string}:必选,time 格式为 HH:mm
  • callback {function (ret)}:执行完读取操作后的回调函数。ret {Object}callback 函数的参数,有两个属性:

    • result {string}:结果三种类型 success, cancel, error
    • data {string}:time 格式为 HH:mm, 仅成功确认的时候存在。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<div class="wrapper">
<div class="group">
<text class="label">Time: </text>
<text class="title">{{value}}</text>
</div>
<div class="group">
<text class="button" @click="pickTime">Pick Time</text>
</div>
</div>
</template>
<script>
const picker = weex.requireModule('picker')
export default {
data () {
return {
value: ''
}
},
methods: {
pickTime () {
picker.pickTime({
value: this.value
}, event => {
if (event.result === 'success') {
this.value = event.data
}
})
}
}
}
</script>
<style scoped>
.wrapper {
flex-direction: column;
justify-content: center;
}
.group {
flex-direction: row;
justify-content: center;
margin-bottom: 40px;
align-items: center;
}
.label {
font-size: 40px;
color: #888888;
}
.title {
font-size: 80px;
color: #41B883;
}
.button {
font-size: 36px;
width: 280px;
color: #41B883;
text-align: center;
padding-top: 25px;
padding-bottom: 25px;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
</style>

WebSocket

WebSocket v0.12+

Updated time: 14/06/2017

Summary

WebSockets 是一种先进的技术, 这使得在用户的 H5/iOS/Android 和一个服务器之间打开一个的交互式通信会话成为可能, 有了这个 API,你可以向服务器发送消息, 并接收事件驱动的响应, 无需轮询服务器的响应

注意:

iOS和h5提供 WebSockets 的 protocol 默认实现,安卓使用需要提供自定义 adapter 实现,source:

API

WebSocket(url, protocol)
创建 WebSockets,并连接服务器

Arguments

  • url {string}: 表示要连接的 URL;
  • protocol {string}: WebSockets 协议

send(data)

通过WebSocket连接向服务器发送数据

Arguments

  • data{string}:要发送到服务器的数据

close(code,reason)
关闭 WebSockets 的链接

Arguments

  • code {number}: 关闭连接的状态号.
  • reason {string}: 关闭的原因

onopen(options)
链接打开的监听

Arguments

  • options {object}: 一个空的对象

onmessage(options)
消息事件的监听器

Arguments

  • options {object}: 服务器返回的消息对象
    • data {string}: 监听器接收的到的消息

onclose(options)
关闭事件的监听器

Arguments

  • options {object}: 监听器接收到的对象
    • code {number}: 服务器返回关闭的状态码
    • reason {string}: 服务器返回的关闭原因
    • wasClean {boolen}: 是否完全关闭.

onerror(options)
错误事件的监听器

Arguments

  • options {object}: 错误信息的事件
    • data {string}: 监听器接收到的信息

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<scroller>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80px ;padding: 20px;color: white">websocket</text>
</div>
<input type="text" placeholder="please input message to send" class="input" autofocus="false" value="" @change="onchange" @input="oninput" ref="input"/>
<div style="flex-direction: row; justify-content: center;">
<text class="button" @click="connect">connect</text>
<text class="button" @click="send">send</text>
<text class="button" @click="close">close</text>
</div>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = send</text>
</div>
<text style="color: black;height: 80px">{{sendinfo}}</text>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = onopen</text>
</div>
<text style="color: black;height: 80px">{{onopeninfo}}</text>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = onmessage</text>
</div>
<text style="color: black;height: 400px">{{onmessage}}</text>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = onclose</text>
</div>
<text style="color: black;height: 80px">{{oncloseinfo}}</text>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = onerror</text>
</div>
<text style="color: black;height: 80px">{{onerrorinfo}}</text>
<div style="background-color: lightgray">
<text class="title" style="height: 80px ;padding: 20px;color: black">method = close</text>
</div>
<text style="color: black;height: 80px">{{closeinfo}}</text>
</div>
</scroller>
</template>
<style scoped>
.input {
font-size: 40px;
height: 80px;
width: 600px;
}
.button {
font-size: 36px;
width: 150px;
color: #41B883;
text-align: center;
padding-top: 25px;
padding-bottom: 25px;
border-width: 2px;
border-style: solid;
margin-right: 20px;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
</style>
<script>
var websocket = weex.requireModule('webSocket')
export default {
data () {
return {
connectinfo: '',
sendinfo: '',
onopeninfo: '',
onmessage: '',
oncloseinfo: '',
onerrorinfo: '',
closeinfo: '',
txtInput:'',
navBarHeight: 88,
title: 'Navigator',
dir: 'examples',
baseURL: ''
}
},
methods: {
connect:function() {
websocket.WebSocket('ws://echo.websocket.org','');
var self = this;
self.onopeninfo = 'connecting...'
websocket.onopen = function(e)
{
self.onopeninfo = 'websocket open';
}
websocket.onmessage = function(e)
{
self.onmessage = e.data;
}
websocket.onerror = function(e)
{
self.onerrorinfo = e.data;
}
websocket.onclose = function(e)
{
self.onopeninfo = '';
self.onerrorinfo = e.code;
}
},
send:function(e) {
var input = this.$refs.input;
input.blur();
websocket.send(this.txtInput);
this.sendinfo = this.txtInput;
},
oninput: function(event) {
this.txtInput = event.value;
},
close:function(e) {
websocket.close();
},
},
}
</script>

Have a try

animation

animation

Updated time: 13/09/2017

流畅且有意义的动画是一个十分有效的提升移动应用用户体验的手段,animation 模块被用于在组件上执行动画。动画可以对组件执行一系列简单的变换 (位置、大小、旋转角度、背景颜色和不透明度)。举个例子,如果有一个 <image> 组件,通过动画你可以对其进行移动、旋转、拉伸或收缩等动作。

API

transition(el, options, callback)

参数

  • el {Element}:将要执行动画的元素,例如指定动画的元素 ref 属性为 test , 可以通过调用 this.refs.test 来获取元素的引用。
  • options {Object}:描述动画过程的对象。
    • options.duration {number}:指定动画的持续时间 (单位是毫秒),默认值是 0,表示没有动画效果。
    • options.delay {number}:指定请求动画操作到执行动画之间的时间间隔 (单位是毫秒),默认值是 0,表示没有延迟,在请求后立即执行动画。
    • options.timingFunction {string}:描述动画执行的速度曲线,用于使动画变化更为平滑。默认值是 linear,表示动画从开始到结束都拥有同样的速度。下表列出了所有合法的属性:
属性名 描述
linear 动画从头到尾的速度是相同的
ease-in 动画速度由慢到快
ease-out 动画速度由快到慢
ease-in-out 动画先加速到达中间点后减速到达终点
cubic-bezier(x1, y1, x2, y2) 在三次贝塞尔函数中定义变化过程,函数的参数值必须处于 0 到 1 之间。更多关于三次贝塞尔的信息请参阅 cubic-bezierBézier curve.
  • options.styles {Object}:设置不同样式过渡效果的键值对,下表列出了所有合法的参数:
参数名 描述 类型 默认值
width 动画执行后应用到组件上的宽度值 length
height 动画执行后应用到组件上的高度值 length
backgroundColor 动画执行后应用到组件上的背景颜色 string none
opacity 动画执行后应用到组件上的不透明度值 介于 0 到 1 间的数值 1
transformOrigin 定义变化过程的中心点. 参数 x-aris 可能的值为 leftcenterright、长度值或百分比值, 参数 y-axis 可能的值为 topcenterbottom、长度值或百分比值 x-axis y-axis center center
transform 定义应用在元素上的变换类型,支持下表列出的属性 object

transform属性的合法值:

名称 描述 值类型 默认值
translate/translateX/translateY 指定元素要移动到的位置 像素值或百分比
rotate 指定元素将被旋转的角度,单位是度 number
scale/scaleX/scaleY 按比例放大或缩小元素 number
rotate/rotateX v0.14+ /rotateY v0.14+ 指定元素将被旋转的角度,单位是度 number
perspective v0.16+ 观察者距离z=0平面的距离,在Android 4.1及以上有效 number 正无穷
  • callback {Function}:动画执行完毕之后的回调
  • needLayout(boolean):节点动画执行时是否产生布局动画即LayoutAnimation

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<template>
<div class="wrapper">
<div ref="test" @click="move" class="box"></div>
</div>
</template>
<script>
const animation = weex.requireModule('animation')
const modal = weex.requireModule('modal')
export default {
methods: {
move () {
var testEl = this.$refs.test;
animation.transition(testEl, {
styles: {
color: '#FF0000',
transform: 'translate(250px, 100px)',
transformOrigin: 'center center'
},
duration: 800, //ms
timingFunction: 'ease',
delay: 0 //ms
}, function () {
modal.toast({ message: 'animation finished.' })
})
}
}
}
</script>
<style scoped>
.box {
width: 250px;
height: 250px;
background-color: #DDD;
}
</style>

try it

slider

<slider>

Updated time: 14/06/2017

<slider> 组件用于在一个页面中展示多个图片,在前端,这种效果被称为 轮播图

子组件

支持任意类型的 Weex 组件作为其子组件。 其中,还支持以下组件作为子组件展示特殊效果:

  • <indicator>:用于显示轮播图指示器效果,必须充当 <slider> 组件的子组件使用。

特性

  • auto-play {boolean}:可选值为 true/false,默认的是 false

该值决定是否自动播放轮播。重置 loadmore 相关的 UI,值不一样就会重置。

  • interval {number}:值为毫秒数,此值设定 slider 切换时间间隔。当 auto-play 值为 true 时生效。

  • infinite {boolean}:循环播放,可选值为 true/false,默认的是 true

  • offset-x-accuracy {number}0.11+:控制 onscroll 事件触发的频率,默认值为10,表示两次 onscroll 事件之间Slider
    Page至少滚动了10px。注意,将该值设置为较小的数值会提高滚动事件采样的精度,但同时也会降低页面的性能。

样式

通用样式:支持所有通用样式

  • 盒模型
  • flexbox 布局
  • position
  • opacity
  • background-color

查看 组件通用样式

事件

  • change: 当轮播索引改变时,触发该事件。

    事件中 event 对象属性:

    • index:展示的图片索引
    • scroll 0.11+: 列表发生滚动时将会触发该事件,事件的默认抽样率为10px,即列表每滚动10px触发一次,可通过属性offset-accuracy设置抽样率。
      体验一下
      事件中 event 对象属性:
    • offsetXRatio {number}`:表示当前页面的偏移比例,取值范围为[-1, 1],负值表示向左侧滚动,正值向右。例如,-0.2表示当前item有20%的区域被滚动到slider左侧边界以外,0 .3表示当前item有30%的区域被滚动到slider右侧边界以外。
  • 通用事件

    支持所有通用事件:

    • click
    • longpress
    • appear
    • disappear

查看 通用事件

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<template>
<div>
<slider class="slider" interval="3000" auto-play="true">
<div class="frame" v-for="img in imageList">
<image class="image" resize="cover" :src="img.src"></image>
</div>
</slider>
</div>
</template>
<style scoped>
.image {
width: 700px;
height: 700px;
}
.slider {
margin-top: 25px;
margin-left: 25px;
width: 700px;
height: 700px;
border-width: 2px;
border-style: solid;
border-color: #41B883;
}
.frame {
width: 700px;
height: 700px;
position: relative;
}
</style>
<script>
export default {
data () {
return {
imageList: [
{ src: 'https://gd2.alicdn.com/bao/uploaded/i2/T14H1LFwBcXXXXXXXX_!!0-item_pic.jpg'},
{ src: 'https://gd1.alicdn.com/bao/uploaded/i1/TB1PXJCJFXXXXciXFXXXXXXXXXX_!!0-item_pic.jpg'},
{ src: 'https://gd3.alicdn.com/bao/uploaded/i3/TB1x6hYLXXXXXazXVXXXXXXXXXX_!!0-item_pic.jpg'}
]
}
}
}
</script>

Try it

scroller

<scroller> v0.6.1+

Updated time: 30/06/2017

<scroller> 是一个竖直的,可以容纳多个排成一列的子组件的滚动器。如果子组件的总高度高于其本身,那么所有的子组件都可滚动。

注意: <scroller> 可以当作根元素或者嵌套元素使用。此组件的滚动方向是垂直方向的形式。

子组件

支持任意类型的 Weex 组件作为其子组件。 其中,还支持以下两个特殊组件作为子组件:

  • <refresh>

    用于给列表添加下拉刷新的功能。

    使用文档请查看 <refresh>

  • <loading>

    <loading> 用法与特性和 <refresh> 类似,用于给列表添加上拉加载更多的功能。

    使用文档请查看 <loading>

特性

  • show-scrollbar {boolean}:可选值为 true/ false,默认值为 true。控制是否出现滚动条。

  • scroll-direction {string}:可选为 horizontal 或者 vertical,默认值为 vertical 。定义滚动的方向。

    • scroll-direction定义了 scroller 的滚动方向,flex-direction 定义了 scroller 的布局方向,两个方向必须一致。
    • scroll-direction 的默认值是 vertical, flex-direction 的默认值是 row
    • 当需要一个水平方向的 scroller 时,使用 scroll-direction:horizontalflex-direction: row
    • 当需要一个竖直方向的 scroller 时,使用 scroll-direction:verticalflex-direction: column。由于这两个值均是默认值,当需要一个竖直方向的 scroller
      时,这两个值可以不设置。
  • loadmoreoffset {number}:默认值为 0,触发 loadmore 事件所需要的垂直偏移距离(设备屏幕底部与页面底部之间的距离)。当页面的滚动条滚动到足够接近页面底部时将会触发 loadmore 这个事件。

  • loadmoreretry {number}:默认值为 0,当 loadmore 失败时是否重置 loadmore 相关的 UI,值不一样就会重置。 该属性已废弃,请使用resetLoadmore()函数实现重置loadmore的操作。

  • offset-accuracy {number} 0.11+:控制onscroll事件触发的频率,默认值为10,表示两次onscroll事件之间列表至少滚动了10px
    。注意,将该值设置为较小的数值会提高滚动事件采样的精度,但同时也会降低页面的性能。

  • offset-accuracy:默认值是0,触发 scroll 事件所需要的垂直偏移距离。

样式

通用样式:支持所有通用样式

事件

  • loadmore v0.5+:如果滚动到底部将会立即触发这个事件,你可以在这个事件的处理函数中加载下一页的列表项。
  • scroll 0.11+: 列表发生滚动时将会触发该事件,事件的默认抽样率为10px,即列表每滚动10px触发一次,可通过属性offset-accuracy设置抽样率。 参见 scroll event demo

    事件中 event 对象属性:

    • contentSize {Object}:列表的内容尺寸
      • width {number}: 列表内容宽度
      • height {number}: 列表内容高度
    • contentOffset {Object}: 列表的偏移尺寸
      • x {number}: x轴上的偏移量
      • y {number}: y轴上的偏移量
  • 通用事件

    支持所有通用事件:

扩展

scrollToElement(node, options)

滚动到列表某个指定项是常见需求,<list> 拓展了该功能支持滚动到指定 <cell>。通过 dom module 访问,更多信息可参考 dom module

resetLoadmore() 0.9+

在默认情况下,触发loadmore事件后,如果列表中内容没有发生变更,则下一次滚动到列表末尾时将不会再次触发loadmore事件,你可以通过调用resetLoadmore()方法来打破这一限制,调用该方法后,下一次滚动到列表末尾时将强制触发loadmore

参数

  • node {node}:指定目标节点。
  • options {Object}
    • offset {number}:一个到其可见位置的偏移距离,默认是0

约束

不允许相同方向的 <list> 或者 <scroller> 互相嵌套,换句话说就是嵌套的 <list>/<scroller> 必须是不同的方向。

举个例子,不允许一个垂直方向的 <list> 嵌套的一个垂直方向的 <scroller> 中,但是一个垂直方向的 <list> 是可以嵌套的一个水平方向的 <list> 或者 <scroller> 中的。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<div class="wrapper">
<scroller class="scroller">
<div class="row" v-for="(name, index) in rows" :ref="'item'+index">
<text class="text" :ref="'text'+index">{{name}}</text>
</div>
</scroller>
<div class="group">
<text @click="goto10" class="button">Go to 10</text>
<text @click="goto20" class="button">Go to 20</text>
</div>
</div>
</template>
<script>
const dom = weex.requireModule('dom')
export default {
data () {
return {
rows: []
}
},
created () {
for (let i = 0; i < 30; i++) {
this.rows.push('row ' + i)
}
},
methods: {
goto10 (count) {
const el = this.$refs.item10[0]
dom.scrollToElement(el, {})
},
goto20 (count) {
const el = this.$refs.item20[0]
dom.scrollToElement(el, { offset: 0 })
}
}
}
</script>
<style scoped>
.scroller {
width: 700px;
height: 700px;
border-width: 3px;
border-style: solid;
border-color: rgb(162, 217, 192);
margin-left: 25px;
}
.row {
height: 100px;
flex-direction: column;
justify-content: center;
padding-left: 30px;
border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: #DDDDDD;
}
.text {
font-size: 45px;
color: #666666;
}
.group {
flex-direction: row;
justify-content: center;
margin-top: 60px;
}
.button {
width: 200px;
padding-top: 20px;
padding-bottom: 20px;
font-size: 40px;
margin-left: 30px;
margin-right: 30px;
text-align: center;
color: #41B883;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
</style>

try it

refresh

<refresh> v0.6.1+

Updated time: 14/06/2017

<refresh><scroller><list> 提供下拉加载功能。用法与特性与 <loading> 类似,<scroller><list> 的子组件,且只能在被 <scroller><list> 包含时才能被正确的渲染。

子组件

  • <text>
  • <image>
  • <loading-indicator>: <refresh><loading> 组件的子组件,拥有默认的动画效果的实现。

特性

  • display {string}:可选值为 show 或者 hide,仅隐藏 <indicator><refresh> 其他子组件依然可见,<refresh> 事件仍会被触发。

样式

支持所有通用样式。

事件

  • refresh: 当 <scroller>/<list> 被下拉时触发。
  • pullingdown: 当 <scroller>/<list> 被下拉时触发,可以从事件的参数对象中获取 dy,pullingDistance, viewHeight, type
    1
    2
    3
    4
    dy: 前后两次回调滑动距离的差值
    pullingDistance: 下拉的距离
    viewHeight: refreshView 高度
    type: "pullingdown" 常数字符串

约束

  • <refresh> 不支持 remove,v0.9 版本会修复。
  • display 值为 showhide。仅隐藏 <indicator><refresh> 其他子组件依然可见,refresh 事件仍会被触发。
    如果需要 <refresh> hide 时隐藏文案并不再触发事件,有两种解决方法:

    1. 修改提示文案,并在 refresh 事件中添加判断逻辑;
    2. v0.9+ 可通过 remove 解决。
  • 只能通过 display 特性进行展示和隐藏,且必须成对出现,即设置 display="show",必须有对应的 display="hide"

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
<scroller class="scroller">
<refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown" :display="refreshing ? 'show' : 'hide'">
<text class="indicator">Refreshing ...</text>
</refresh>
<div class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</div>
</scroller>
</template>
<script>
const modal = weex.requireModule('modal')
export default {
data () {
return {
refreshing: false,
lists: [1, 2, 3, 4, 5]
}
},
methods: {
onrefresh (event) {
console.log('is refreshing')
modal.toast({ message: 'refresh', duration: 1 })
this.refreshing = true
setTimeout(() => {
this.refreshing = false
}, 2000)
},
onpullingdown (event) {
console.log('is onpulling down')
modal.toast({ message: 'pulling down', duration: 1 })
}
}
}
</script>
<style scoped>
.indicator {
color: #888888;
font-size: 42px;
text-align: center;
}
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: #DDDDDD;
background-color: #F5F5F5;
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>

try it

更多示例可查看 <list>

loading

<loading> v0.6.1+

Updated time: 14/06/2017

<loading><scroller><list> 提供上拉加载功能。用法与特性与 <refresh> 类似, 是 <scroller><list> 的子组件,且只能在被 <scroller><list> 包含时才能被正确的渲染。

子组件

  • <text>
  • <image>
  • <loading-indicator>: <refresh><loading> 组件的子组件,拥有默认的动画效果的实现。

特性

  • display {string}:可选值为 show 或者 hide,仅隐藏 <indicator><loading> 其他子组件依然可见,loading 事件仍会被触发。

样式

支持所有通用样式。

事件

  • loading:加载时被触发。

约束

  • <loading> 不支持 remove,v0.9 版本会修复。
  • display 值为 showhide。仅隐藏 <indicator><loading> 其他子组件依然可见,loading 事件仍会被触发。

    如果需要 <loading> hide 时隐藏文案并不再触发事件,有两种解决方法:

    1. 修改提示文案,并在 loading 事件中添加判断逻辑;
    2. v0.9+ 可通过 remove 解决。
      只能通过 display 特性进行展示和隐藏,且必须成对出现,即设置 display="show",必须有对应的 display="hide"

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<scroller class="scroller">
<div class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</div>
<loading class="loading" @loading="onloading" :display="showLoading">
<text class="indicator">Loading ...</text>
</loading>
</scroller>
</template>
<script>
const modal = weex.requireModule('modal')
const LOADMORE_COUNT = 4
export default {
data () {
return {
showLoading: 'hide',
lists: [1, 2, 3, 4, 5]
}
},
methods: {
onloading (event) {
modal.toast({ message: 'loading', duration: 1 })
this.showLoading = 'show'
setTimeout(() => {
const length = this.lists.length
for (let i = length; i < length + LOADMORE_COUNT; ++i) {
this.lists.push(i + 1)
}
this.showLoading = 'hide'
}, 1500)
}
}
}
</script>
<style scoped>
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: #DDDDDD;
background-color: #F5F5F5;
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
.loading {
justify-content: center;
}
.indicator {
color: #888888;
font-size: 42px;
padding-top: 20px;
padding-bottom: 20px;
text-align: center;
}
</style>

Try it

cell

<cell>

Updated time: 14/06/2017

用于定义列表中的子列表项,类似于 HTML 中的 ul 之于 li。Weex 会对 <cell> 进行高效的内存回收以达到更好的性能,该组件必须作为<list> 组件的子组件, 这是为了优化滚动时的性能。

子组件

支持所有 Weex 的组件作为它的子组件。

属性

  • keep-scroll-position {boolean}: v0.11+ List 插入数据后是否保持上次滚动的位置

样式

注意:

由于 <cell> 本身是一个容器,其布局由 <list> 进行管理,你不能给 <cell> 设定flex值。 <cell>的宽度等于父组件 <list> 的宽度,并且 <cell> 高度自适应,指定 margin 样式也不起作用。

  • 通用样式:支持所有通用样式

事件

  • 通用事件

    支持所有通用事件:

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<template>
<list class="list" @loadmore="fetch" loadmoreoffset="10">
<cell class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</cell>
</list>
</template>
<script>
const modal = weex.requireModule('modal')
const LOADMORE_COUNT = 4
export default {
data () {
return {
lists: [1, 2, 3, 4, 5]
}
},
methods: {
fetch (event) {
modal.toast({ message: 'loadmore', duration: 1 })
setTimeout(() => {
const length = this.lists.length
for (let i = length; i < length + LOADMORE_COUNT; ++i) {
this.lists.push(i + 1)
}
}, 800)
}
}
}
</script>
<style scoped>
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>

try it

waterfall

<waterfall> v0.11.0+

Updated time: 14/06/2017

提供瀑布流布局的组件

子组件

注意: 和list一样, waterfall 只支持特定类型的组件: cell, header, refresh, loading 和 fixed-position 组件.

  • cell: 瀑布流中的每个元素
  • header: 主要用于表示横跨多列的元素,可以通过css的position属性设置为sticky

特性

  • column-width : 描述瀑布流每一列的列宽
    • auto: 意味着列宽是被其他属性所决定的(比如 column-count)
    • <length>: 最佳列宽,实际的列宽可能会更宽(需要填充剩余的空间), 或者更窄(如果剩余空间比列宽还要小)。 该值必须大于0
  • column-count: 描述瀑布流的列数
    • auto: 意味着列数是被其他属性所决定的(比如 column-width)
    • <integer>: 最佳列数,column-width 和 column-count 都指定非0值, 则 column-count 代表最大列数。
  • column-gap: 列与列的间隙. 如果指定了 normal ,则对应 32.

其他支持的属性参见 List Component Attributes

样式

通用样式:支持所有通用样式

事件

  • 通用事件

支持所有通用事件:

API

滚动到列表某个指定项是常见需求,<waterfall> 拓展了该功能支持滚动到指定 <cell> 或者 <header>。通过 dom module 访问,更多信息可参考 dom module

示例

参见 playground waterfall example