全局异常处理
This commit is contained in:
@@ -2,4 +2,5 @@ export interface ApiResponse {
|
||||
code?: number;
|
||||
message?: string;
|
||||
data?: any;
|
||||
err?: string;
|
||||
}
|
||||
|
||||
@@ -227,6 +227,11 @@ const fetchPosts = async () => {
|
||||
title: searchText.value || undefined
|
||||
})
|
||||
const data = (res as any).data || res || {}
|
||||
const errMsg = (res as any).err
|
||||
if (errMsg) {
|
||||
message.error(errMsg)
|
||||
return
|
||||
}
|
||||
posts.value = data.list || []
|
||||
total.value = data.total || 0
|
||||
} catch (error) {
|
||||
@@ -266,13 +271,20 @@ const handleCreatePost = async () => {
|
||||
|
||||
createLoading.value = true
|
||||
try {
|
||||
await postApiForumPostsCreate({
|
||||
const res = await postApiForumPostsCreate({
|
||||
boardId: Number("1"),//默认板块IDtodo
|
||||
userId: currentUserId.value,
|
||||
title: createForm.title,
|
||||
content: createForm.content,
|
||||
coverImage: createForm.coverImage,
|
||||
status: 'NORMAL'
|
||||
})
|
||||
const data = (res as any).data || res || {}
|
||||
const errMsg = (res as any).err
|
||||
if (errMsg) {
|
||||
message.error(errMsg)
|
||||
return
|
||||
}
|
||||
message.success('情报发布成功')
|
||||
createModalVisible.value = false
|
||||
fetchPosts()
|
||||
|
||||
Reference in New Issue
Block a user