HomeDocs
Skip to main content

editor

Description

The editor component is a rich text editor that allows editing of images and text. The editor exports content in both HTML format with tags and plain text format.

Attribute Description

AttributeTypeDefault ValueRequiredDescription
defaultHtmlStringnoneNoThe initial content of the editor
editorPlaceholderStringnoneNoThe placeholder text for the editor
doneStringnoneNoThe label for the completion button
imgsArraynoneNoThe images to be inserted at the cursor position

Events

Event NameDescriptionCallback Parameters
onChangeTriggered when the content of the editor changescontent (the updated content)
choseMediaTriggered when the image button in the toolbar is clickednumber (maximum number of images to insert)
onSaveNotifies the user to save the contentcontent (the current content of the editor)

Example

<view class="wrap">
<editor
:defaultHtml="defaultHtml"
:done="done"
:imgs="imgs"
bind:choseMedia="onChoseMedia"
:editorPlaceholder="editorPlaceholder"
bind:onSave="onSave"
bind:onChange="onChange"
/>
</view>
Page({
data: {
defaultHtml: '<p>hello editor</p>',
editorPlaceholder: 'input',
done: 'done',
imgs: [],
id: null,
},
onLoad({ id }) {
this.setData({
id,
});
},
onChange(data) {
console.log('onChange===', data);
},
onChoseMedia(count) {
dlt.chooseMedia({
count,
success: (res) => {
try {
const images = JSON.parse(res.images) || [];
this.setData({
imgs: images,
});
} catch (error) {}
},
});
},
onSave(data) {
console.log('onSave====', data);
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.