wangEditor v5图片粘贴到输入框后 如何实现自己的逻辑 取消原有的样式?
const editor = new wangEditor('#editor')
editor.config.pasteFilterStyle = false // 取消粘贴时的样式
editor.config.pasteIgnoreImg = true // 忽略粘贴的图片
editor.config.customAlert = function (info) { // 自定义提示信息的方式
console.log(info)
}
editor.config.pasteTextHandle = function (content) { // 粘贴事件
const wrapper = document.createElement('div')
wrapper.innerHTML = content
const imgs = wrapper.querySelectorAll('img')
for (let i = 0; i < imgs.length; i++) {
const img = imgs[i]
img.removeAttribute('style') // 取消样式
img.removeAttribute('width') // 取消宽度
img.removeAttribute('height') // 取消高度
}
const textContent = wrapper.textContent
editor.cmd.do('insertHTML', textContent) // 插入文本
}
editor.create()
MENU_CONF: {
uploadImage: {
async customUpload (file, insertFn) {
// this.loading = true;
// const quill = this.$refs.myQuillEditor.quill;
// // 上传图片
const fd = new FormData()
fd.append('resource', file)
try {
const { data, code } = await uploadRichTextImage(fd)
// 如果上传成功
if (code === 200) {
// file 即选中的文件
// 自己实现上传,并得到图片 url alt href
// 最后插入图片
console.log(data)
insertFn(data, 'poppy-size-chart', data)
// this.loading = false
}
} catch (err) {
Message.error('Insert image error')
} finally {
// this.loading = false
}
}
}
}