56 lines
1.1 KiB
Vue
56 lines
1.1 KiB
Vue
<template>
|
|
<div ref="editor" class="rich-editor"></div>
|
|
</template>
|
|
<script>
|
|
import { onMounted, onBeforeUnmount, ref, watch } from 'vue'
|
|
import WangEditor from 'wangeditor'
|
|
export default {
|
|
props: {
|
|
value: {
|
|
type: String,
|
|
default: ''
|
|
}
|
|
},
|
|
setup(props, context) {
|
|
watch(
|
|
() => props.value,
|
|
() => {
|
|
console.log(props.value)
|
|
if (instance) {
|
|
instance.txt.html(props.value)
|
|
}
|
|
}
|
|
)
|
|
const editor = ref()
|
|
let instance
|
|
onMounted(() => {
|
|
instance = new WangEditor(editor.value)
|
|
// Object.assign(instance.config, {
|
|
// onchange(val) {
|
|
// context.emit('change', val)
|
|
// }
|
|
// });
|
|
instance.create()
|
|
})
|
|
onBeforeUnmount(() => {
|
|
instance.destroy()
|
|
instance = null
|
|
})
|
|
function getContent() {
|
|
return editor.value.innerText
|
|
}
|
|
return {
|
|
editor,
|
|
getContent
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.rich-editor {
|
|
position: relative;
|
|
white-space: pre-line;
|
|
z-index: 1 !important;
|
|
}
|
|
</style>
|