index.html

  1. <td>
  2. <button type="button" class="btn btn-danger" @click ="onDelete(item._id)" >删除</button>
  3. </td>
  4. <script>
  5. new Vue({
  6. el:"#app",
  7. data:{
  8. movies:[]
  9. },
  10. methods:{
  11. doDelete(id){
  12. console.log(id)
  13. this.movies = this.movies.filter(item=>item._id != id);
  14. $.ajax({
  15. url:"http://localhost:8080/doDelete",
  16. method:"post",
  17. data:{
  18. id
  19. }
  20. }).then(res=>{
  21. console.log(res)
  22. })
  23. }
  24. }
  25. </script>

index.js

  1. //index.js
  2. router.post("/doDelete",async ctx=>{
  3. console.log(ctx.request.body);
  4. var {id} = ctx.request.body;
  5. await Top250Model.remove({_id:id})
  6. })