cmc-web/packages/common/components/rich-text-editor/index.vue

53 lines
1.0 KiB
Vue
Raw Normal View History

2024-08-20 12:11:31 +00:00
<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>