글쓰기 로컬 자동 저장 추가

This commit is contained in:
2026-05-02 10:35:28 +09:00
parent 6bc697bd95
commit 722e027f18
10 changed files with 223 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ const id = computed(() => String(route.params.id || ''))
const saving = ref(false)
const deleting = ref(false)
const errorMessage = ref('')
const postForm = ref(null)
const { data: post } = await useFetch(() => `/admin/api/posts/${id.value}`)
@@ -34,6 +35,7 @@ const savePost = async (payload) => {
})
post.value = updatedPost
postForm.value?.clearAutosave()
} catch (error) {
errorMessage.value = error?.data?.message || '글을 저장하지 못했습니다.'
} finally {
@@ -99,6 +101,6 @@ const deletePost = async () => {
<p v-if="errorMessage" class="admin-post-edit__error mb-5 rounded border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
{{ errorMessage }}
</p>
<AdminPostForm :initial-post="post" submit-label="변경 저장" :saving="saving" @submit="savePost" />
<AdminPostForm ref="postForm" :initial-post="post" submit-label="변경 저장" :saving="saving" @submit="savePost" />
</section>
</template>

View File

@@ -5,6 +5,7 @@ definePageMeta({
const saving = ref(false)
const errorMessage = ref('')
const postForm = ref(null)
/**
* 새 게시물 저장
@@ -21,6 +22,7 @@ const savePost = async (payload) => {
body: payload
})
postForm.value?.clearAutosave()
await navigateTo(`/admin/posts/${post.id}`)
} catch (error) {
errorMessage.value = error?.data?.message || '글을 저장하지 못했습니다.'
@@ -43,6 +45,6 @@ const savePost = async (payload) => {
<p v-if="errorMessage" class="admin-post-editor__error mb-5 rounded border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
{{ errorMessage }}
</p>
<AdminPostForm submit-label=" 저장" :saving="saving" @submit="savePost" />
<AdminPostForm ref="postForm" submit-label=" 저장" :saving="saving" @submit="savePost" />
</section>
</template>