1e41f4b71Sopenharmony_ci# list
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci列表包含一系列相同宽度的列表项。适合连续、多行呈现同类数据,例如图片和文本。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 该组件从从API version 4 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 子组件
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci仅支持<[list-item](js-lite-components-container-list-item.md)>。
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## 属性
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
19e41f4b71Sopenharmony_ci| id | string | - | 否 | 组件的唯一标识。 |
20e41f4b71Sopenharmony_ci| style | string | - | 否 | 组件的样式声明。 |
21e41f4b71Sopenharmony_ci| class | string | - | 否 | 组件的样式类,用于引用样式表。 |
22e41f4b71Sopenharmony_ci| ref | string | - | 否 | 用来指定指向子元素的引用信息,该引用将注册到父组件的$refs 属性对象上。 |
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## 事件
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 |
28e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
29e41f4b71Sopenharmony_ci| scrollend | - | 列表滑动已经结束。 |
30e41f4b71Sopenharmony_ci| click | - | 点击动作触发该事件。 |
31e41f4b71Sopenharmony_ci| longpress | - | 长按动作触发该事件。 |
32e41f4b71Sopenharmony_ci| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | 组件上快速滑动后触发。 |
33e41f4b71Sopenharmony_ci| scrolltop<sup>8+</sup> | - | 当前列表已滑动到顶部位置。 |
34e41f4b71Sopenharmony_ci| scrollbottom<sup>8+</sup> | - | 当前列表已滑动到底部位置。 |
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci## 样式
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
40e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
41e41f4b71Sopenharmony_ci| flex-direction | string | column | 否 | 设置flex容器主轴的方向,指定flex项如何放置在flex容器中,可选值为:<br/>-&nbsp;column:主轴为纵向。<br/>-&nbsp;row:主轴为横向。<br/>其他组件默认值为row,在list组件中默认值为column。轻量级智能穿戴不支持动态修改。 |
42e41f4b71Sopenharmony_ci| width | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | - | 否 | 设置组件自身的宽度。<br/><br/>未设置时组件宽度默认为0。 |
43e41f4b71Sopenharmony_ci| height | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | - | 否 | 设置组件自身的高度。<br/><br/>未设置时组件高度默认为0。 |
44e41f4b71Sopenharmony_ci| padding | &lt;length&gt; | 0 | 否 | 使用简写属性设置所有的内边距属性。<br/>&nbsp;&nbsp;该属性可以有1到4个值:<br/>-&nbsp;指定一个值时,该值指定四个边的内边距。<br/>-&nbsp;指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。<br/>-&nbsp;指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。<br/>-&nbsp;指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。 |
45e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | &lt;length&gt; | 0 | 否 | 设置左、上、右、下内边距属性。 |
46e41f4b71Sopenharmony_ci| margin | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | 0 | 否 | 使用简写属性设置所有的外边距属性,该属性可以有1到4个值。<br/>-&nbsp;只有一个值时,这个值会被指定给全部的四个边。<br/>-&nbsp;两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。<br/>-&nbsp;三个值时,第一个值被匹配给上,&nbsp;第二个值被匹配给左和右,第三个值被匹配给下。<br/>-&nbsp;四个值时,会依次按上、右、下、左的顺序匹配&nbsp;(即顺时针顺序)。 |
47e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | 0 | 否 | 设置左、上、右、下外边距属性。 |
48e41f4b71Sopenharmony_ci| border-width | &lt;length&gt; | 0 | 否 | 使用简写属性设置元素的所有边框宽度。 |
49e41f4b71Sopenharmony_ci| border-color | &lt;color&gt; | black | 否 | 使用简写属性设置元素的所有边框颜色。 |
50e41f4b71Sopenharmony_ci| border-radius | &lt;length&gt; | - | 否 | border-radius属性是设置元素的外边框圆角半径。 |
51e41f4b71Sopenharmony_ci| background-color | &lt;color&gt; | - | 否 | 设置背景颜色。 |
52e41f4b71Sopenharmony_ci| opacity<sup>5+</sup> | number | 1 | 否 | 元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。 |
53e41f4b71Sopenharmony_ci| display | string | flex | 否 | 确定一个元素所产生的框的类型,可选值为:<br/>-&nbsp;flex:弹性布局。<br/>-&nbsp;none:不渲染此元素。 |
54e41f4b71Sopenharmony_ci| [left\|top] | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>6+</sup> | - | 否 | left\|top确定元素的偏移位置。<br/>-&nbsp;left属性规定元素的左边缘。该属性定义了定位元素左外边距边界与其包含块左边界之间的偏移。<br/>-&nbsp;top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。 |
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci## 方法
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 |
60e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
61e41f4b71Sopenharmony_ci| scrollTo | {&nbsp;index:&nbsp;number(指定位置)&nbsp;} | list滑动到指定index的item位置。 |
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## 示例
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci```html
68e41f4b71Sopenharmony_ci<!-- index.hml -->
69e41f4b71Sopenharmony_ci<div class="container">
70e41f4b71Sopenharmony_ci  <list class="todo-wraper">
71e41f4b71Sopenharmony_ci    <list-item for="{{todolist}}" class="todo-item">
72e41f4b71Sopenharmony_ci      <text class="todo-title">{{$item.title}}</text>
73e41f4b71Sopenharmony_ci      <text class="todo-title">{{$item.date}}</text>
74e41f4b71Sopenharmony_ci    </list-item>
75e41f4b71Sopenharmony_ci  </list>
76e41f4b71Sopenharmony_ci</div>
77e41f4b71Sopenharmony_ci```
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci```js
81e41f4b71Sopenharmony_ci// index.js
82e41f4b71Sopenharmony_ciexport default {
83e41f4b71Sopenharmony_ci  data: {
84e41f4b71Sopenharmony_ci    todolist: [{
85e41f4b71Sopenharmony_ci      title: '刷题',
86e41f4b71Sopenharmony_ci      date: '2021-12-31 10:00:00',
87e41f4b71Sopenharmony_ci    }, {
88e41f4b71Sopenharmony_ci      title: '看电影',
89e41f4b71Sopenharmony_ci      date: '2021-12-31 20:00:00',
90e41f4b71Sopenharmony_ci    }],
91e41f4b71Sopenharmony_ci  },
92e41f4b71Sopenharmony_ci}
93e41f4b71Sopenharmony_ci```
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci```css
97e41f4b71Sopenharmony_ci/* index.css */
98e41f4b71Sopenharmony_ci.container {
99e41f4b71Sopenharmony_ci  display: flex;
100e41f4b71Sopenharmony_ci  justify-content: center;
101e41f4b71Sopenharmony_ci  align-items: center;
102e41f4b71Sopenharmony_ci  left: 0px;
103e41f4b71Sopenharmony_ci  top: 0px;
104e41f4b71Sopenharmony_ci  width: 454px;
105e41f4b71Sopenharmony_ci  height: 454px;
106e41f4b71Sopenharmony_ci}
107e41f4b71Sopenharmony_ci.todo-wraper {
108e41f4b71Sopenharmony_ci  width: 454px;
109e41f4b71Sopenharmony_ci  height: 300px;
110e41f4b71Sopenharmony_ci}
111e41f4b71Sopenharmony_ci.todo-item {
112e41f4b71Sopenharmony_ci  width: 454px;
113e41f4b71Sopenharmony_ci  height: 80px;
114e41f4b71Sopenharmony_ci  flex-direction: column;
115e41f4b71Sopenharmony_ci}
116e41f4b71Sopenharmony_ci.todo-title {
117e41f4b71Sopenharmony_ci  width: 454px;
118e41f4b71Sopenharmony_ci  height: 40px;
119e41f4b71Sopenharmony_ci  text-align: center;
120e41f4b71Sopenharmony_ci}
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci![list](figures/list-lite.png)
124