# Media Components
# Media Component Description
| Component | Description | Minimum Version | Remarks |
|---|---|---|---|
| audio | Audio | 1.0.0 | |
| image | Image | 1.0.0 | |
| video | Video | 1.0.0 | |
| camera | Camera | 2.9.3 | |
| live-player | Real-time audio playback | 2.10.1 | |
| live-pusher | Real-time audio recording | 2.10.1 | |
| voip-room | Multi-person audio/video call | Not supported |
# audio
Please Note
The audio component is no longer maintained. Please use the wx.createInnerAudio API for audio playback.
| Attribute | Type | Default Value | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| id | string | No | Unique identifier for the audio component | 1.0.0 | |
| src | string | No | The resource address of the audio to be played | 1.0.0 | |
| loop | boolean | false | No | Whether to loop playback | 1.0.0 |
| controls | boolean | false | No | Whether to display default controls | 1.0.0 |
| poster | string | No | The image resource address of the audio cover on the default controls. If the controls attribute value is false, setting poster is invalid | 1.0.0 | |
| name | string | Unknown audio | No | The audio name on the default controls. If the controls attribute value is false, setting name is invalid | 1.0.0 |
| author | string | Unknown author | No | The author name on the default controls. If the controls attribute value is false, setting author is invalid | 1.0.0 |
| binderror | eventhandle | No | Triggered when an error occurs, detail = {errMsg:MediaError.code} | 1.0.0 | |
| bindplay | eventhandle | No | Triggered when playback starts/resumes | 1.0.0 | |
| bindpause | eventhandle | No | Triggered when playback is paused | 1.0.0 | |
| bindtimeupdate | eventhandle | No | Triggered when playback progress changes, detail = {currentTime, duration} | 1.0.0 | |
| bindended | eventhandle | No | Triggered when playback reaches the end | 1.0.0 |
# image
| Attribute | Type | Default Value | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| src | string | No | Image resource address | 2.11.4 | |
| mode | string | scaleToFill | No | Image cropping and scaling mode | 2.11.4 |
| binderror | eventhandle | No | Triggered when an error occurs, event.detail = {errMsg} | 2.11.4 | |
| bindload | eventhandle | No | Triggered when the image finishes loading, event.detail = {height, width} | 2.11.4 | |
| webp | boolean | false | No | By default, webP format is not parsed; only network resources are supported | Not supported |
| lazy-load | boolean | false | No | Image lazy loading; loading begins only when about to enter a certain range (three screens above and below) | 2.12.2 |
| show-menu-by-longpress | boolean | false | No | Enable long-press image to show the Mini-Program code recognition menu | Not supported |
# Legal values of mode
| Value | Description | Minimum Version |
|---|---|---|
| scaleToFill | Scaling mode; does not maintain aspect ratio, stretches the image width and height to completely fill the image element | |
| aspectFit | Scaling mode; maintains aspect ratio, ensures the long side of the image is fully displayed. In other words, the image can be displayed completely. | |
| aspectFill | Scaling mode; maintains aspect ratio, only ensures the short side of the image is fully displayed. In other words, the image is usually complete only in the horizontal or vertical direction, and the other direction will be cropped. | |
| widthFix | Scaling mode; width remains unchanged, height changes automatically, maintaining the original image aspect ratio | |
| heightFix | Scaling mode; height remains unchanged, width changes automatically, maintaining the original image aspect ratio | |
| top | Cropping mode; does not scale the image, only displays the top area of the image | |
| bottom | Cropping mode; does not scale the image, only displays the bottom area of the image | |
| center | Cropping mode; does not scale the image, only displays the middle area of the image | |
| left | Cropping mode; does not scale the image, only displays the left area of the image | |
| right | Cropping mode; does not scale the image, only displays the right area of the image | |
| top left | Cropping mode; does not scale the image, only displays the top-left area of the image | |
| top right | Cropping mode; does not scale the image, only displays the top-right area of the image | |
| bottom left | Cropping mode; does not scale the image, only displays the bottom-left area of the image | |
| bottom right | Cropping mode; does not scale the image, only displays the bottom-right area of the image |
# live-player
Using the live-player component on iOS requires integrating the Live Streaming SDK
For iOS integration of the Extension SDK / Live Streaming SDK, please refer to "Mini-Program SDK-iOS SDK-iOS Integration-Live Streaming SDK"
Using the live-player component on Android requires integrating the LiveSDK
For Android integration of LiveSDK, please refer to "Mini-Program SDK-Android SDK-Android Integration-LiveSDK"
Using the live-player component on HarmonyOS requires integrating the LiveSDK
For HarmonyOS integration of LiveSDK, please refer to "Mini-Program SDK-HarmonyOS Harmony SDK-HarmonyOS Harmony Integration-LiveSDK"
| Attribute | Type | Default Value | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| src | string | No | Audio/video address. Currently supports flv, rtmp formats; webrtc format depends on the oem parameter to enable | 3.0.50 | |
| oem | string | No | "srs" //open source service, "zlmedia" //ZLmedia, "nginx" //Nginx, "anyrtc" //Anyrtc, "aliyun" //Alibaba, "tencent" //Tencent, "huawei" //Huawei, "qiniu" //Qiniu, "aws" // Aws, "max" | 3.4.4 harmony: Not supported yet | |
| mode | string | live | No | Mode | Not supported yet |
| autoplay | boolean | false | No | Auto play | 3.0.50 |
| muted | boolean | false | No | Whether to mute | 3.0.50 |
| orientation | string | vertical | No | Screen orientation | Not supported yet |
| object-fit | string | contain | No | Fill mode; optional values are contain, fillCrop | 3.0.50 |
| background-mute | boolean | false | No | Whether to mute when entering the background (deprecated; mutes by default when going to background) | Not supported yet |
| min-cache | number | 1 | No | Minimum buffer, in s (RTC mode recommends 0.2s) | Not supported yet |
| max-cache | number | 3 | No | Maximum buffer, in s (RTC mode recommends 0.8s). The buffer is used to resist network fluctuations; the more buffered data, the better the network resilience, but the greater the latency. | Not supported yet |
| sound-mode | string | speaker | No | Sound output method | Not supported yet |
| auto-pause-if-navigate | boolean | true | No | Whether to automatically pause the real-time audio/video playback on this page when navigating to other pages of this Mini-Program | 3.3.1 SDK:2.44.1 |
| auto-pause-if-open-native | boolean | true | No | Whether to automatically pause the real-time audio/video playback on this page when navigating to other native pages | 3.3.1 SDK:2.44.1 |
| picture-in-picture-mode | string/Array | No | Set the picture-in-picture mode: push, pop, empty string, or set multiple modes via an array (e.g., ["push", "pop"]) | 3.3.1 SDK:2.44.1 | |
| bindstatechange | eventhandle | No | Playback state change event, detail = {code} | 3.0.50 | |
| bindfullscreenchange | eventhandle | No | Full-screen change event, detail = {direction, fullScreen} | Not supported yet | |
| bindnetstatus | eventhandle | No | Network status notification, detail = {info} | 3.0.50 | |
| bindaudiovolumenotify | eventhandler | No | Playback volume notification, detail = {} | 3.0.50 | |
| bindenterpictureinpicture | eventhandler | No | Player enters picture-in-picture | android, harmony: Not supported yet | |
| bindleavepictureinpicture | eventhandler | No | Player exits picture-in-picture | android, harmony: Not supported yet |
# Legal values of mode
| Value | Description | Minimum Version |
|---|---|---|
| live | Live streaming | |
| RTC | Real-time call; this mode has lower latency |
# Legal values of orientation
| Value | Description | Minimum Version |
|---|---|---|
| vertical | Vertical | |
| horizontal | Horizontal |
# Legal values of object-fit
| Value | Description | Minimum Version |
|---|---|---|
| contain | The long side of the image fills the screen; the short side area will be filled with black | |
| fillCrop | The image fills the screen; the part beyond the display area will be cropped |
# Legal values of sound-mode
| Value | Description | Minimum Version |
|---|---|---|
| speaker | Speaker | |
| ear | Earpiece |
# Legal values of picture-in-picture-mode
| Value | Description | Minimum Version |
|---|---|---|
| [] | Cancel picture-in-picture | |
| push | Trigger picture-in-picture on route push | |
| pop | Trigger picture-in-picture on route pop |
# live-pusher
Using the live-pusher component on iOS requires integrating the Live Streaming SDK
For iOS integration of the Extension SDK or Live Streaming SDK, please refer to "Mini-Program SDK-iOS SDK-iOS Integration-Live Streaming SDK"
Using the live-pusher component on Android requires integrating the LiveSDK
For Android integration of LiveSDK, please refer to "Mini-Program SDK-Android SDK-Android Integration-LiveSDK"
Using the live-pusher component on HarmonyOS requires integrating the LiveSDK
For HarmonyOS integration of LiveSDK, please refer to "Mini-Program SDK-HarmonyOS Harmony SDK-HarmonyOS Harmony Integration-LiveSDK"
| Attribute | Type | Default Value | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| url | string | No | Stream push address. Currently only rtmp format is supported | 3.0.50 | |
| mode | string | RTC | No | SD (Standard Definition), HD (High Definition), FHD (Ultra HD), RTC (Real-time call) | Not supported yet |
| autopush | boolean | false | No | Auto push | 3.0.50 |
| muted | boolean | false | No | Whether to mute. To be deprecated; can be replaced by enable-mic | 3.0.50 |
| enable-camera | boolean | true | No | Enable camera | 3.0.50 |
| auto-focus | boolean | true | No | Auto focus | Not supported yet |
| orientation | string | vertical | No | Screen orientation | Not supported yet |
| beauty | number | 0 | No | Beauty; value range 0-9, 0 means off | Not supported yet |
| whiteness | number | 0 | No | Whitening; value range 0-9, 0 means off | Not supported yet |
| aspect | string | 9:16 | No | Aspect ratio; optional values are 3:4, 9:16 | Not supported yet |
| min-bitrate | number | 200 | No | Minimum bitrate | Not supported yet |
| max-bitrate | number | 1000 | No | Maximum bitrate | Not supported yet |
| audio-quality | string | high | No | High audio quality (48KHz) or low audio quality (16KHz); values are high, low | Not supported yet |
| waiting-image | string | No | The waiting image for stream pushing when entering the background | Not supported yet | |
| waiting-image-hash | string | No | MD5 value of the waiting image resource | Not supported yet | |
| zoom | boolean | false | No | Adjust focal length | Not supported yet |
| device-position | string | front | No | Front or back; values are front, back | 3.0.50 |
| background-mute | boolean | false | No | Whether to mute when entering the background (deprecated; mutes by default when going to background) | Not supported yet |
| mirror | boolean | false | No | Set whether the pushed stream image is mirrored; the effect is reflected in live-player | Not supported yet |
| remote-mirror | boolean | false | No | Same as the mirror attribute; mirror will be deprecated later | Not supported yet |
| local-mirror | string | auto | No | Control whether the local preview image is mirrored | Not supported yet |
| audio-reverb-type | number | 0 | No | Audio reverb type | Not supported yet |
| enable-mic | boolean | true | No | Enable or disable the microphone | 3.0.50 |
| enable-agc | boolean | false | No | Whether to enable audio automatic gain control | Not supported yet |
| enable-ans | boolean | false | No | Whether to enable audio noise suppression | Not supported yet |
| audio-volume-type | string | auto | No | Volume type | Not supported yet |
| video-width | number | 360 | No | Resolution width of the pushed video stream | Not supported yet |
| video-height | number | 640 | No | Resolution height of the pushed video stream | Not supported yet |
| beauty-style | string | smooth | No | Set the beauty type | Not supported yet |
| pictureInPictureMode | string/Array | No | Set the picture-in-picture mode: push, pop, empty string, or set multiple modes via an array (e.g., ["push", "pop"]) | 3.0.0 harmony: Not supported yet | |
| custom-effect | string | standard | No | Whether to enable custom effects | Not supported yet |
| voice-changer-type | number | 0 | No | Voice change effect | Not supported yet |
| skin-whiteness | number | 0 | No | Custom effect whitening | Not supported yet |
| skin-smoothness | number | 0 | No | Custom effect skin smoothing | Not supported yet |
| face-thinness | number | 0 | No | Custom effect face slimming | Not supported yet |
| eye-bigness | number | 0 | No | Custom effect eye enlarging | Not supported yet |
| fps | number | 15 | No | Frame rate | Not supported yet |
| filter | string | standard | No | Set color filter | Not supported yet |
| bindstatechange | eventhandle | No | State change event, detail = {code} | 3.0.50 | |
| bindnetstatus | eventhandle | No | Network status notification, detail = {info} | 3.0.50 | |
| binderror | eventhandle | No | Rendering error event, detail = {errMsg, errCode} | 3.0.50 | |
| bindbgmstart | eventhandle | No | Triggered when background audio starts playing | Not supported yet | |
| bindbgmprogress | eventhandle | No | Triggered when background audio progress changes, detail = {progress, duration} | Not supported yet | |
| bindbgmcomplete | eventhandle | No | Triggered when background audio playback is complete | Not supported yet | |
| bindaudiovolumenotify | eventhandle | No | Returns the volume level collected by the microphone | Not supported yet | |
| bindenterpictureinpicture | eventhandle | No | Callback for entering picture-in-picture | 3.4.1 harmony: Not supported yet | |
| bindleavepictureinpicture | eventhandle | No | Callback for exiting picture-in-picture | 3.4.1 harmony: Not supported yet |
# Legal values of orientation
| Value | Description | Minimum Version |
|---|---|---|
| vertical | Vertical | |
| horizontal | Horizontal |
# Legal values of local-mirror
| Value | Description | Minimum Version |
|---|---|---|
| auto | Front camera is mirrored, rear camera is not mirrored | |
| enable | Both front and rear cameras are mirrored | |
| disable | Neither front nor rear cameras are mirrored |
# Valid values for audio-reverb-type
| Value | Description | Minimum Version |
|---|---|---|
| 0 | Off | |
| 1 | KTV | |
| 2 | Small room | |
| 3 | Auditorium | |
| 4 | Deep | |
| 5 | Loud | |
| 6 | Metallic | |
| 7 | Magnetic |
# Valid values for audio-volume-type
| Value | Description | Minimum Version |
|---|---|---|
| auto | Auto | |
| media | Media volume | |
| voicecall | Call volume |
# Valid values for beauty-style
| Value | Description | Minimum Version |
|---|---|---|
| smooth | Smooth beautify | |
| nature | Natural beautify |
# Valid values for filter
| Value | Description | Minimum Version |
|---|---|---|
| standard | Standard | |
| pink | Pink | |
| nostalgia | Nostalgia | |
| blues | Blues | |
| romantic | Romantic | |
| cool | Cool | |
| fresher | Fresh | |
| solor | Japanese | |
| aestheticism | Aesthetic | |
| whitening | Whitening | |
| cerisered | Cherry Red |
# video
| Attribute | Type | Default | Required | Description | Support |
|---|---|---|---|---|---|
| src | string | Yes | The resource address of the video to play, supports network paths and local temporary paths | iOS:✅ Android:✅ Harmony:✅ | |
| duration | number | No | Specify the video duration | iOS:✅ Android:✅ Harmony:✅ | |
| controls | boolean | true | No | Whether to show the default playback controls (play/pause button, playback progress, time) | iOS:✅ Android:✅ Harmony:✅ |
| danmu-list | Array | No | Danmu list | iOS:✅ Android:✅ Harmony:✅ | |
| danmu-btn | boolean | false | No | Whether to show the danmu button, only effective at initialization, cannot be changed dynamically | iOS:✅ Android:✅ Harmony:✅ |
| enable-danmu | boolean | false | No | Whether to display danmu, only effective at initialization, cannot be changed dynamically | iOS:✅ Android:✅ Harmony:✅ |
| enable-view-danmu | boolean | false | No | Whether to display danmu, only effective under same-layer video. When this configuration is used, the enable-danmu setting no longer takes effect. Supported since Base Library 3.5.9 | iOS:✅ Android:✅ Harmony:✅ |
| autoplay | boolean | false | No | Whether to autoplay | iOS:✅ Android:✅ Harmony:✅ |
| loop | boolean | false | No | Whether to loop | iOS:✅ Android:✅ Harmony:✅ |
| muted | boolean | false | No | Whether to play muted | iOS:✅ Android:✅ Harmony:✅ |
| initial-time | number | 0 | No | Specify the initial playback position of the video | iOS:✅ Android:✅ Harmony:✅ |
| direction | number | No | Set the video direction in fullscreen. If not specified, it is automatically determined based on the aspect ratio | iOS:✅ Android:✅ Harmony:✅ | |
| show-progress | boolean | true | No | If not set, it is only displayed when the width is greater than 240 | iOS:✅ Android:✅ Harmony:✅ |
| show-fullscreen-btn | boolean | true | No | Whether to show the fullscreen button | iOS:✅ Android:✅ Harmony:✅ |
| show-play-btn | boolean | true | No | Whether to show the play button in the bottom control bar of the video | iOS:✅ Android:✅ Harmony:✅ |
| show-center-play-btn | boolean | true | No | Whether to show the play button in the center of the video | iOS:✅ Android:✅ Harmony:✅ |
| enable-progress-gesture | boolean | true | No | Whether to enable the gesture for controlling progress | iOS:✅ Android:✅ Harmony:✅ |
| object-fit | string | contain | No | The display mode of the video when the video size is inconsistent with the video container size | iOS:✅ Android:✅ Harmony:✅ |
| poster | string | No | The network resource address or cloud file ID (2.3.0) of the video cover image. If the controls attribute value is false, setting poster is invalid | iOS:✅ Android:✅ Harmony:✅ | |
| show-mute-btn | boolean | false | No | Whether to show the mute button | iOS:✅ Android:✅ Harmony:✅ |
| title | string | No | The title of the video, displayed at the top in fullscreen | iOS:✅ Android:✅ Harmony:✅ | |
| play-btn-position | string | bottom | No | The position of the play button | iOS:✅ Android:✅ Harmony:✅ |
| enable-play-gesture | boolean | false | No | Whether to enable the play gesture, i.e., double-tap to toggle play/pause | iOS:✅ Android:✅ Harmony:✅ |
| auto-pause-if-navigate | boolean | true | No | Whether to automatically pause the video playback on this page when navigating to other pages of this Mini-Program | iOS:✅ Android:✅ Harmony:✅ |
| auto-pause-if-open-native | boolean | true | No | Whether to automatically pause the video on this page when navigating to native pages of other APPs | iOS:✅ Android:✅ Harmony:✅ |
| vslide-gesture | boolean | false | No | Whether to enable the brightness and volume adjustment gesture in non-fullscreen mode (same as page-gesture) | iOS:✅ Android:✅ Harmony:❌ |
| vslide-gesture-in-fullscreen | boolean | true | No | Whether to enable the brightness and volume adjustment gesture in fullscreen mode | iOS:✅ Android:✅ Harmony:❌ |
| poster-for-crawler | string | Yes | Used to display as the video cover in scenarios such as search. It is recommended to use a video cover image without a play icon. Only network addresses are supported | iOS:❌ Android:❌ Harmony:❌ | |
| show-casting-button | boolean | false | No | Show the casting button. Effective under same-layer rendering on Android, supports DLNA protocol; supports AirPlay and DLNA protocols on iOS | iOS:✅ Android:✅ Harmony:❌ |
| picture-in-picture-mode | string/Array | No | Set the picture-in-picture mode: push, pop, empty string, or set multiple modes via an array (e.g., ["push", "pop"]) | iOS:✅ Android:✅ Harmony:1.3.6 | |
| picture-in-picture-show-progress | boolean | false | No | Whether to show playback progress in picture-in-picture mode | iOS:✅ Android:✅ Harmony:❌ |
| enable-auto-rotation | boolean | false | No | Whether to enable automatic fullscreen when the phone is in landscape mode. Effective when the system setting for auto-rotate is enabled | iOS:✅ Android:✅ Harmony:❌ |
| show-screen-lock-button | boolean | false | No | Whether to show the screen lock button, only displayed in fullscreen. Controls the operation of the control bar after locking the screen | iOS:✅ Android:✅ Harmony:❌ |
| show-snapshot-button | boolean | false | No | Whether to show the snapshot button, only displayed in fullscreen | iOS:✅ Android:✅ Harmony:❌ |
| show-background-playback-button | boolean | false | No | Whether to show the background audio playback button | iOS:❌ Android:✅ Harmony:❌ |
| background-poster | string | No | The notification bar icon after entering background audio playback | iOS:✅ Android:✅ Harmony:✅ | |
| bindplay | eventhandle | No | Triggered when playback starts/resumes, triggers the play event | iOS:✅ Android:✅ Harmony:✅ | |
| bindpause | eventhandle | No | Triggered when playback is paused, triggers the pause event | iOS:✅ Android:✅ Harmony:✅ | |
| bindended | eventhandle | No | Triggered when playback reaches the end, triggers the ended event | iOS:✅ Android:✅ Harmony:✅ | |
| bindtimeupdate | eventhandle | No | Triggered when playback progress changes, event.detail = { currentTime, duration }. | iOS:✅ Android:✅ Harmony:✅ | |
| bindfullscreenchange | eventhandle | No | Triggered when the video enters and exits fullscreen, event.detail = { fullScreen, direction }, valid values for direction are vertical or horizontal | iOS:✅ Android:✅ Harmony:✅ | |
| bindwaiting | eventhandle | No | Triggered when the video is buffering | iOS:✅ Android:✅ Harmony:❌ | |
| binderror | eventhandle | No | Triggered when a video playback error occurs | iOS:✅ Android:✅ Harmony:✅ | |
| bindprogress | eventhandle | No | Triggered when loading progress changes, only supports one segment of loading. event.detail = { buffered }, percentage | iOS:✅ Android:✅ Harmony:❌ | |
| bindloadedmetadata | eventhandle | No | Triggered when video metadata loading is complete. event.detail = { width, height, duration } | iOS:✅ Android:✅ Harmony:❌ | |
| bindcontrolstoggle | eventhandle | No | Triggered when toggling the display/hide of controls. event.detail = { show } | iOS:✅ Android:✅ Harmony:✅ | |
| bindseekcomplete | eventhandler | No | Triggered when seek is complete | iOS:✅ Android:✅ Harmony:✅ | |
| bindenterpictureinpicture | eventhandler | No | Player enters picture-in-picture | iOS:❌ Android:❌ Harmony:1.3.6 | |
| bindleavepictureinpicture | eventhandler | No | Player enters picture-in-picture | iOS:❌ Android:❌ Harmony:1.3.6 |
Note:
- Base Library 2.11.2 needs to be used with SDK 2.34.1
- Some attributes are not supported for setting in the IDE, mainly involving fullscreen, gestures, picture-in-picture mode, etc. It is recommended to check on a real device
# native-view
Native view container
| Attribute | Type | Default | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| type | string | camera | Yes | Native container type, once set it cannot be changed | |
| options | string | {} | No | Custom parameters passed to the native component, using the JSON data string format result | |
| bindontask | eventhandle | No | Receive events sent by the native component |
Sample code
<native-view
type="{{type}}"
options="{{options}}"
bindready="bindonready"
></native-view>
Note: To globally listen to native-view events, refer to the onCustomEvent API
Please note
To implement native-view on the HarmonyOS side, use xComponent proxy
# camera
| Attribute | Type | Default | Required | Description | Support |
|---|---|---|---|---|---|
| mode | string | normal | No | Application mode, only effective at initialization, cannot be changed dynamically | iOS:✅ Android:✅ Harmony:✅ |
| resolution | string | medium | No | Resolution, dynamic modification is not supported | iOS:✅ Android:✅ Harmony:✅ |
| device-position | string | back | No | Camera direction | iOS:✅ Android:✅ Harmony:✅ |
| flash | string | auto | No | Flash, values are auto, on, off, torch | iOS:✅ Android:✅ Harmony:✅ |
| frame-size | string | medium | No | Specify the desired camera frame data size | iOS:✅ Android:✅ Harmony:✅ |
| bindstop | eventhandle | No | Triggered when the camera terminates abnormally, such as exiting to the background | iOS:✅ Android:✅ Harmony:✅ | |
| binderror | eventhandle | No | Triggered when the user does not allow the use of the camera | iOS:✅ Android:✅ Harmony:✅ | |
| bindinitdone | eventhandle | No | Triggered when camera initialization is complete, e.detail = {maxZoom} | iOS:✅ Android:✅ Harmony:✅ | |
| bindscancode | eventhandle | No | Triggered when scan code recognition succeeds, only effective when mode="scanCode" | iOS:✅ Android:✅ Harmony:✅ |
# x-component
Custom native component
| Attribute | Type | Default | Required | Description | Minimum Version |
|---|---|---|---|---|---|
| tag | string | No | Component type identifier | 3.7.3 | |
| data | object | {} | No | Custom parameters passed to the native component | 3.7.3 |
Sample code
<x-component id='XComponent' tag='button' data="{{xData}}" style="width:400px;height:300px;"/>
<button bindtap='bindTap'>tap</button>
Page({
data:{
xData:{
name: 'abc',
age: 123,
ad: {
a: 'b',
list: [1, 2, 3]
}
}
},
onLoad() {
// Get the context via the id of x-component
this.xContext = wx.createXComponentContext('XComponent')
// Listen to events sent by native to this x-component
this.xContext.on('onTestEvent', res => {
console.log('onTestEvent', res)
})
},
bindTap(){
// Send event to native
this.xContext.publish('appletEvent',{foo:'bar'})
}
})