editor emit 추가

This commit is contained in:
ckx6954 2024-12-17 09:55:52 +09:00
parent fb26f6d701
commit fb88e248f8
5 changed files with 29 additions and 14 deletions

7
src/common/utils.js Normal file
View File

@ -0,0 +1,7 @@
export const wait = timeToDelay => new Promise(resolve => setTimeout(resolve, timeToDelay));
export const isEmpty = (value) => {
if (value == "" || value == null || value == undefined || (value != null && typeof value == "object" && !Object.keys(value).length))
return true;
return false;
}

View File

@ -1,11 +1,15 @@
<template> <template>
<Editor :api-key="editorKey" :init="init" /> <Editor v-model="content"
:api-key="editorKey" :init="init" />
</template> </template>
<script setup> <script setup>
import Editor from '@tinymce/tinymce-vue'; import Editor from '@tinymce/tinymce-vue';
import { nextTick, onBeforeUnmount, onMounted, reactive } from 'vue'; import { reactive, ref, watch, watchEffect } from 'vue';
import { wait } from '@/common/utils';
const emit = defineEmits(['update:data']);
const content = ref('');
const editorKey = '71nhna4fusscfsf8qvo9cg3ul4uydwt346izxa6ra6zwjsz7'; const editorKey = '71nhna4fusscfsf8qvo9cg3ul4uydwt346izxa6ra6zwjsz7';
const init = reactive({ const init = reactive({
menubar: false, menubar: false,
@ -94,12 +98,14 @@ const init = reactive({
styles: { 'text-align': 'justify' }, styles: { 'text-align': 'justify' },
}, },
}, },
setup(editor) { setup(editor) {
editor.on('init', async () => { editor.on('init', async () => {
// //
await wait(500); await wait(500);
const targetElement = document.querySelector('[aria-label="Insert/edit code sample"]'); const targetElement = document.querySelector('[aria-label="Insert/edit code sample"]');
//editor.notificationManager <-- editor
targetElement.addEventListener('click', async () => { targetElement.addEventListener('click', async () => {
// //
await wait(200); await wait(200);
@ -139,15 +145,17 @@ const init = reactive({
} }
}); });
}); });
}, },
}); });
const wait = timeToDelay => new Promise(resolve => setTimeout(resolve, timeToDelay)); watchEffect(() =>{
emit('update:data', content.value)
})
// emit file ~ // emit file ~
</script> </script>
<style scoped> <style scoped>
</style> </style>

View File

@ -52,14 +52,14 @@ const prop = defineProps({
}, },
}); });
const emits = defineEmits(['inputVal']) const emits = defineEmits(['update:data'])
const updateInput = function (event) { const updateInput = function (event) {
//Type Number maxlength //Type Number maxlength
if (event.target.value.length > prop.maxlength) { if (event.target.value.length > prop.maxlength) {
event.target.value = event.target.value.slice(0, prop.maxlength); event.target.value = event.target.value.slice(0, prop.maxlength);
} }
emits('inputVal', event.target.value); emits('update:data', event.target.value);
}; };
</script> </script>

View File

@ -43,14 +43,13 @@ const prop = defineProps({
}, },
}); });
const emit = defineEmits(['selectVal']) const emit = defineEmits(['update:data'])
const selectData = ref(prop.value); const selectData = ref(prop.value);
watchEffect(() => { watchEffect(() => {
emit('selectVal',selectData); emit('update:data',selectData);
}) })
</script> </script>
<style> <style>

View File

@ -9,11 +9,11 @@
<div class="col-xl-12"> <div class="col-xl-12">
<div class="card-body"> <div class="card-body">
<FormInput title="제목" name="title" :is-essential="true" @input-val="title = $event" /> <FormInput title="제목" name="title" :is-essential="true" @update:data="title = $event" />
<FormSelect title="카테고리" name="cate" :is-essential="true" :data="categoryList" @select-val="category = $event" /> <FormSelect title="카테고리" name="cate" :is-essential="true" :data="categoryList" @update:data="category = $event" />
<FormInput title="비밀번호" name="pw" type="password" :is-essential="true" @input-val="password = $event" /> <FormInput title="비밀번호" name="pw" type="password" :is-essential="true" @update:data="password = $event" />
<FormFile /> <FormFile />
@ -23,7 +23,7 @@
<span class="text-red">*</span> <span class="text-red">*</span>
</label> </label>
<div class="col-md-12"> <div class="col-md-12">
<TEditor /> <TEditor @update:data="content = $event"/>
</div> </div>
</div> </div>
@ -49,6 +49,7 @@ const categoryList = ['자유', '임시', '공지사항'];
const title = ref(''); const title = ref('');
const password = ref(''); const password = ref('');
const category = ref(''); const category = ref('');
const content = ref('');
</script> </script>
<style> <style>