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