1# swiper 2 3滑动容器,提供切换子组件显示的能力。 4 5> **说明:** 6> 7> 该组件从从API version 4 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8 9 10## 子组件 11 12支持除<list>之外的子组件。 13 14 15## 属性 16 17| 名称 | 类型 | 默认值 | 必填 | 描述 | 18| -------- | -------- | -------- | -------- | -------- | 19| index | number | 0 | 否 | 当前在容器中显示的子组件的索引值。 | 20| loop | boolean | true | 否 | 是否开启循环轮播。<br/> | 21| duration | number | - | 否 | 子组件切换的动画时长。 | 22| vertical | boolean | false | 否 | 是否为纵向滑动,纵向滑动时采用纵向的指示器。<br/>不支持动态修改。 | 23| id | string | - | 否 | 组件的唯一标识。 | 24| style | string | - | 否 | 组件的样式声明。 | 25| class | string | - | 否 | 组件的样式类,用于引用样式表。 | 26| ref | string | - | 否 | 用来指定指向子元素的引用信息,该引用将注册到父组件的$refs 属性对象上。 | 27 28 29## 事件 30 31| 名称 | 参数 | 描述 | 32| -------- | -------- | -------- | 33| change | { index: currentIndex } | 当前显示的组件索引变化时触发该事件。 | 34| click | - | 点击动作触发该事件。 | 35| longpress | - | 长按动作触发该事件。 | 36| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | 组件上快速滑动后触发。 | 37 38 39## 样式 40 41| 名称 | 类型 | 默认值 | 必填 | 描述 | 42| -------- | -------- | -------- | -------- | -------- | 43| width | <length> \| <percentage><sup>5+</sup> | - | 否 | 设置组件自身的宽度。<br/><br/>未设置时组件宽度默认为0。 | 44| height | <length> \| <percentage><sup>5+</sup> | - | 否 | 设置组件自身的高度。<br/><br/>未设置时组件高度默认为0。 | 45| padding | <length> | 0 | 否 | 使用简写属性设置所有的内边距属性。<br/> 该属性可以有1到4个值:<br/>- 指定一个值时,该值指定四个边的内边距。<br/>- 指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。<br/>- 指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。<br/>- 指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。 | 46| padding-[left\|top\|right\|bottom] | <length> | 0 | 否 | 设置左、上、右、下内边距属性。 | 47| margin | <length> \| <percentage><sup>5+</sup> | 0 | 否 | 使用简写属性设置所有的外边距属性,该属性可以有1到4个值。<br/>- 只有一个值时,这个值会被指定给全部的四个边。<br/>- 两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。<br/>- 三个值时,第一个值被匹配给上, 第二个值被匹配给左和右,第三个值被匹配给下。<br/>- 四个值时,会依次按上、右、下、左的顺序匹配 (即顺时针顺序)。 | 48| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | 否 | 设置左、上、右、下外边距属性。 | 49| border-width | <length> | 0 | 否 | 使用简写属性设置元素的所有边框宽度。 | 50| border-color | <color> | black | 否 | 使用简写属性设置元素的所有边框颜色。 | 51| border-radius | <length> | - | 否 | border-radius属性是设置元素的外边框圆角半径。 | 52| background-color | <color> | - | 否 | 设置背景颜色。 | 53| opacity<sup>5+</sup> | number | 1 | 否 | 元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。 | 54| display | string | flex | 否 | 确定一个元素所产生的框的类型,可选值为:<br/>- flex:弹性布局。<br/>- none:不渲染此元素。 | 55| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | 否 | left\|top确定元素的偏移位置。<br/>- left属性规定元素的左边缘。该属性定义了定位元素左外边距边界与其包含块左边界之间的偏移。<br/>- top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。 | 56 57 58## 示例 59 60 61```html 62<!-- xxx.hml --> 63<swiper class="container" index="{{index}}"> 64 <div class="swiper-item primary-item"> 65 <text>1</text> 66 </div> 67 <div class="swiper-item warning-item"> 68 <text>2</text> 69 </div> 70 <div class="swiper-item success-item"> 71 <text>3</text> 72 </div> 73</swiper> 74``` 75 76 77```css 78/* xxx.css */ 79.container { 80 left: 0px; 81 top: 0px; 82 width: 454px; 83 height: 454px; 84} 85.swiper-item { 86 width: 454px; 87 height: 454px; 88 justify-content: center; 89 align-items: center; 90} 91.primary-item { 92 background-color: #007dff; 93} 94.warning-item { 95 background-color: #ff7500; 96} 97.success-item { 98 background-color: #41ba41; 99} 100``` 101 102 103```js 104/* xxx.js */ 105export default { 106 data: { 107 index: 1 108 } 109} 110``` 111 112 113