Update application code and dependencies
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
'use client'
|
||||
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
export default function DeleteNewsButton({ id }: { id: number }) {
|
||||
const router = useRouter()
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (!confirm("确定要删除这条新闻吗?")) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/admin/news/${id}`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
router.refresh()
|
||||
}
|
||||
} catch (error) {
|
||||
alert("删除失败")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={handleDelete}
|
||||
className="text-red-600 hover:text-red-700 text-sm"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user