<Toolbar
style="border-bottom: 1px solid #ccc"
:editor="editorRef"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<Editor
:style="{ height: `${props.height}px`, overflowy: 'hidden' }"
v-model="valueHtml"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="handleCreated"
@onChange="handleOnChange"
@onFocus="handleFocus"
@onBlur="handleBlur"
/>
//封装的element的上传组件
<Upload name="image"
:showList="false"
:limit="1"
:accept="'.png,.jpg,.jpeg,.gif'"
@onSuccess="onSuccess"
>
</Upload>
ts
const mode = ref("default");
// 编辑器实例,必须用 shallowRef
const editorRef = shallowRef();
const editor = editorRef.value;
// 内容 HTML
const valueHtml:any = ref(props.Html);
// 当编辑器创建的时候
const handleCreated = (editor) => {
editorRef.value = editor;
};
//上传成功后
const onSuccess = (data:any) =>{
console.log('上传成功:'+JSON.stringify(data))
const img = `<img src="${data.url}" alt="${data.name}"/>`
//上传成功后把图片插入内容
editorRef.value.dangerouslyInsertHtml(img)
}
const editorConfig: Partial<IEditorConfig> = {
// TS 语法
placeholder: "请输入内容...",
readOnly: props.readOnly,
MENU_CONF: {
uploadImage: {
allowedFileTypes: ['image/*'],
// 自定义选择图片
async customBrowseAndUpload(insertFn) {
document.querySelector('.el-upload__input').click() //这里使用element的上传组件
},
}
},
};