vue中使用富文本插入小程序卡片
首先新建mp.js文件夹
import mp from '@/utils/mp'
Quill.register(mp, true)
import { Quill } from 'vue-quill-editor'
const BlockEmbed = Quill.import('blots/block/embed')
const Link = Quill.import('formats/link')
class mp extends BlockEmbed {
static create(value) {
const node = super.create(value)
node.setAttribute('data-miniprogram-appid', value.appid)
node.setAttribute('data-miniprogram-path', value.path)
node.setAttribute('data-miniprogram-title', value.title)
node.setAttribute('data-miniprogram-imageurl', value.imageurl)
return node
}
static sanitize(url) {
return Link.sanitize(url)
}
static value(domNode) {
return {
appid: domNode.getAttribute('data-miniprogram-appid'),
path: domNode.getAttribute('data-miniprogram-path'),
title: domNode.getAttribute('data-miniprogram-title'),
imageurl: domNode.getAttribute('data-miniprogram-imageurl')
}
}
}
mp.blotName = 'link'
mp.tagName = 'mp-miniprogram'
export default mp