js-components-basic-piece.md 2.3 KB
Newer Older
E
ester.zhou 已提交
1
# piece
Z
zengyawen 已提交
2

E
ester.zhou 已提交
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
>  **NOTE**
>
>  This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version.

The **\<piece>** component provides an entrance piece that can contain images and text. It is usually used to display receivers, for example, email recipients or message recipients.

## Child Components

Not supported


## Attributes

In addition to the [universal attributes](../arkui-js/js-components-common-attributes.md), the following attributes are supported.

| Name    | Type   | Mandatory| Description                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
| content  | string  | Yes  | Text content of the operational piece.                                            |
| closable | boolean | No  | Whether to display the delete icon for the operational piece. When users click the delete icon, it triggers the close event.<br>Default value: **false**|
| icon     | string  | No  | URL of the delete icon for the operational piece. The value can be a local path.                         |


## Styles

The [universal styles](../arkui-js/js-components-common-styles.md) are supported.

>  **NOTE**
>
>  By default, text and images are placed in the middle of the **\<piece>** component.


## Events

In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.

| Name   | Parameter  | Description                                 |
| ----- | ---- | ----------------------------------- |
| close | -    | Triggered when users click the delete icon of the operational piece. You can delete this component by using the **if** directive.|

## Methods

The [universal methods](../arkui-js/js-components-common-methods.md) are supported.


## Example

```html
Z
zengyawen 已提交
50
<!-- xxx.hml-->
Z
zengyawen 已提交
51 52 53
<div class="container" >
  <piece if="{{first}}" content="example"></piece>
  <piece if="{{second}}" content="example" closable="true" onclose="closeSecond"></piece>
Z
zengyawen 已提交
54 55 56
</div>
```

E
ester.zhou 已提交
57
```css
Z
zengyawen 已提交
58 59 60 61 62 63 64 65 66
/* xxx.css */
.container {
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}
```

E
ester.zhou 已提交
67
```js
Z
zengyawen 已提交
68 69 70 71 72 73 74 75 76 77 78 79
// xxx.js
export default {
  data: {
    first: true,
    second: true
  },
  closeSecond(e) {
    this.second = false;
  }
}
```

E
ester.zhou 已提交
80
![11-5](figures/11-5.gif)