logo

该视频仅会员有权观看

立即开通课程「Node 框架 Express 实践」权限。

¥
199
/ 年
  • Open the 'post service' file, define and export a function named deletePostById, marked with async.
  • The function accepts a postId parameter, which can be a string or number.
  • Declare a variable response equal to await, call an API using HTTP client to the address 'post/' + postId, with the message set to 'sit'.
  • Return the response.json.
  • Open the 'postToolbar' component, declare a router using useRouter from 'next/router'.
  • Add a delete icon to the component's view inside a div with an image; the src of the image is '/icon/', with the SVG's alt attribute set to 'delete content'.
  • Set the icon's width and height to 20 and bind an onClick event, using async to mark the event handler.
  • In the handler, await the execution of deletePostById with a postId parameter.
  • After content deletion, call router.refresh() to refresh the page.
  • Convert the component to a client-side component using the 'client' directive at the top of the component declaration.
  • Test in the browser by opening the content list page, find the content posted by the current user, and click the delete icon to remove the content.