diff --git a/src/common/common.js b/src/common/common.js new file mode 100644 index 0000000..e761219 --- /dev/null +++ b/src/common/common.js @@ -0,0 +1,49 @@ +/* + 작성자 : 공현지 + 작성일 : 2025-01-17 + 수정자 : + 수정일 : + 설명 : 공통 스크립트 +*/ +import Quill from 'quill'; + +/* + *템플릿 사용법 : $common.변수 + *setup() 사용법 : + const { appContext } = getCurrentInstance(); + const $common = appContext.config.globalProperties.$common; + $common.변수 +*/ +const common = { + // JSON 문자열로 Delta 타입을 변환 + contentToHtml(content) { + try { + if (content.startsWith('{') || content.startsWith('[')) { + // Delta 형식으로 변환 + const delta = JSON.parse(content); + const quill = new Quill(document.createElement('div')); + quill.setContents(delta); + return quill.root.innerHTML; // HTML 반환 + } + return content; // 이미 HTML일 경우 그대로 반환 + } catch (error) { + console.error('콘텐츠 변환 오류:', error); + return content; // 오류 발생 시 원본 반환 + } + }, + // Delta 타입을 JSON 문자열로 변환 + deltaAsJson(content) { + if (content && content.ops) { + return JSON.stringify(content.ops); // Delta 객체에서 ops 속성만 JSON 문자열로 변환 + } + console.error('잘못된 Delta 객체:', content); + return null; // Delta 객체가 아니거나 ops가 없을 경우 null 반환 + } + +} + +export default { + install(app) { + app.config.globalProperties.$common = common; + } +}; diff --git a/src/components/editor/QEditor.vue b/src/components/editor/QEditor.vue index 8fb4538..321f170 100644 --- a/src/components/editor/QEditor.vue +++ b/src/components/editor/QEditor.vue @@ -46,20 +46,27 @@
+ + +
내용을 확인해주세요.
- \ No newline at end of file + diff --git a/src/main.js b/src/main.js index 12ed27d..05f6a5c 100644 --- a/src/main.js +++ b/src/main.js @@ -5,13 +5,15 @@ import App from './App.vue' import router from '@/router' import dayjs from '@p/dayjs' import ToastModal from '@c/modal/ToastModal.vue'; - +import common from '@/common/common.js' + const pinia = createPinia() pinia.use(piniaPersist) const app = createApp(App) app.use(router) .use(pinia) + .use(common) .use(dayjs) .component('ToastModal',ToastModal) .mount('#app')