Skip to content

Commit

Permalink
update: vote backend
Browse files Browse the repository at this point in the history
  • Loading branch information
yuantuo666 committed Aug 26, 2023
1 parent b15d365 commit adf2009
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions pages/vote/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,51 @@ const reset = () => {
})
}
const submit = () => {
const submit = async () => {
if (selectedTime.value.length === 0) {
ElNotification.error({
title: '错误',
message: '请至少选择一个时间',
})
return
}
console.log(selectedTime.value)
const postData = {
vote_id: 1,
data: selectedTime.value
}
const { data, error }: { data: Ref<any>, error: Ref<any> } = 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,
})
}
</script>

Expand Down

0 comments on commit adf2009

Please sign in to comment.