From adf200905f2a916b3b40cb08c8a50c619e80bd5c Mon Sep 17 00:00:00 2001 From: yuantuo666 Date: Sun, 27 Aug 2023 00:26:11 +0800 Subject: [PATCH] update: vote backend --- pages/vote/[id].vue | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/pages/vote/[id].vue b/pages/vote/[id].vue index eb5a730..a755bd0 100644 --- a/pages/vote/[id].vue +++ b/pages/vote/[id].vue @@ -108,7 +108,7 @@ const reset = () => { }) } -const submit = () => { +const submit = async () => { if (selectedTime.value.length === 0) { ElNotification.error({ title: '错误', @@ -116,7 +116,43 @@ const submit = () => { }) return } - console.log(selectedTime.value) + + const postData = { + vote_id: 1, + data: selectedTime.value + } + + const { data, error }: { data: Ref, error: Ref } = await useFetch('http://127.0.0.1:8787/vote', { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + method: 'POST', + body: JSON.stringify(postData) + }) + console.log(data.value) + if (error.value) { + ElNotification.error({ + title: '网络错误', + message: '请求失败,' + error.value?.message, + }) + return + } + + if (data.value.code !== 200) { + ElNotification.error({ + title: '投票失败', + message: data.value.msg, + }) + return + } + + + ElNotification.success({ + title: '投票成功', + message: data.value.msg, + }) + }