From 21a81c0f86fadea363043b0b003db58324f6de8a Mon Sep 17 00:00:00 2001 From: Cksheuen <116556497+Cksheuen@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:24:39 +0800 Subject: [PATCH] fixed fetch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了fetch不到数据的问题,但保留了无法第一时间渲染的问题、篇幅过长无法正常载入以及部分格式无法统一的问题 --- components/FileIndex.vue | 4 +- components/RichEditor.vue | 2 +- layouts/default.vue | 13 +- nuxt.config.ts | 2 +- pages/editor.vue | 6 +- pages/list.vue | 16 +- pages/posts/[id].vue | 19 +- ...00\346\254\241\344\276\213\344\274\232.md" | 708 ++++++++++++++++++ 8 files changed, 740 insertions(+), 30 deletions(-) create mode 100644 "posts/\347\254\254\344\270\200\346\254\241\344\276\213\344\274\232.md" diff --git a/components/FileIndex.vue b/components/FileIndex.vue index 9414663..e1ec05e 100644 --- a/components/FileIndex.vue +++ b/components/FileIndex.vue @@ -21,11 +21,9 @@ function clickHandler(index: number) {
diff --git a/components/RichEditor.vue b/components/RichEditor.vue index ee650fe..e15ef2e 100644 --- a/components/RichEditor.vue +++ b/components/RichEditor.vue @@ -72,7 +72,7 @@ function handleCreated(editor) { async function update() { const editor = editorRef.value const markdown = turndownService.turndown(editor.getHtml()) - await useFetch('/api/post/setNew', { + const { data, pending, error, refresh } = await useFetch('/api/post/setNew', { method: 'POST', body: JSON.stringify({ id: editState.currentEditFileName, diff --git a/layouts/default.vue b/layouts/default.vue index c2c4caa..2ec5711 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -1,12 +1,15 @@ diff --git a/nuxt.config.ts b/nuxt.config.ts index 982857c..6a3d500 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -66,4 +66,4 @@ export default defineNuxtConfig({ enabled: true, }, }, -}) \ No newline at end of file +}) diff --git a/pages/editor.vue b/pages/editor.vue index 3708837..910a9fc 100644 --- a/pages/editor.vue +++ b/pages/editor.vue @@ -7,12 +7,12 @@ interface Text { } const text = ref({ markdown: '', html: '' }) editState.$subscribe(async (state) => { - const data = await useFetch(`/api/post/${editState.currentEditFileName}`, { + const { data, pending, error, refresh } = await useFetch(`/api/post/${editState.currentEditFileName}`, { options: { method: 'GET', lazy: true, }, - }).data.value + }) text.value.markdown = data?.fileContent text.value.html = data?.contentHtml @@ -26,7 +26,7 @@ function changeHtml(value: any) {