๊ฐ๋ฐ์ผ์ง
tui-editor (TOAST UI Editor) vue3 <script setup> ์ ์ฉ๋ฒ
yyza
2023. 7. 13. 15:15
๋ฐ์ํ
๐ฅtui-editor ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
https://github.com/nhn/tui.editor
GitHub - nhn/tui.editor: ๐๐ Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
๐๐ Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible. - GitHub - nhn/tui.editor: ๐๐ Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
github.com
npm install --save @toast-ui/vue-editor
๐ฅ Vue3 ํ๋ก์ ํธ์ tui-editor๊ตฌ์ฑํ๊ธฐ
import Editor from '@toast-ui/editor';
import '@toast-ui/editor/dist/toastui-editor.css';
๐ฅ tui-editor ์ฌ์ฉ ์ด์
์ฒ์์ผ๋ก HTML Editor๋ฅผ ์ฌ์ฉํ๊ฑด Ck-editor์๋๋ฐ tui-editor๊ฐ ์ค์น๋ ์ฌ์ฉ๋ฒ์ ์์ด ๋ ๊ฐ๋จํ๊ณ ๋ช ๋ฃํ๊ธฐ ๋๋ฌธ์ ์ฌ์ฉํ๊ฒ ๋์์ต๋๋ค.
๐ฅtui-editor ์ ์ฉ ๋ฐฉ๋ฒ
tui-editor๊ฐ ๊ธฐ์กด vue2๊น์ง๋ ์ง์์ ํ์์ผ๋ vue3๋ถํฐ๋ vue3์ ํจ๊ป Tui.Editor๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ง์ ๋ํผ ํด์ผํฉ๋๋ค.
<template>
// ref์ฌ์ฉํ์ฌ ์๋ํฐ value ์ ์ฉ
<div ref="editor" />
//์์ฑํ ๋ด์ฉ ๋ถ๋ฌ์์ html ์ ์ฉ
<div v-html="testHtml.value"></div>
</template>
<scipt setup>
import { onMounted, ref, watch, onUnmounted } from 'vue';
import Editor from '@toast-ui/editor';
import '@toast-ui/editor/dist/toastui-editor.css';
const props = defineProps({
modelValue: {
type: String,
required: false,
default: '',
},
});
const emit = defineEmits(['update:modelValue']);
const editor = ref();
const editorValid = ref();
const testHtml = ref();
//๋ง์ดํธ๋ ๋ Editor ์์ฑ
onMounted(() => {
editorValid.value = new Editor({
el: editor.value,
height: '500px',
//'wysiwyg', 'markdown' ํ 1
initialEditType: 'wysiwyg',
events: {
change: () => emit('update:modelValue', editorValid.value.getMarkdown()),
},
});
});
//์์ฑํ ๋ด์ฉ ๋ถ๋ฌ์์ html ์ ์ฉ
const testValid = (e) => {
testHtml.value = editorValid.value.getHTML()
};
</script>
์ฃผ์ํ ์ ์ onMounted ๋ ๋ editor๋ฅผ ์ ์ฉํ๋ฏ๋ก ์ ์ฉํ ํด๋น elements๊ฐ Hide๋์ด์์์ ์๋ฌ ๋ฐ์
๋ฐ์ํ