1.绑定事件

  1. <button type="button" class="btn btn-danger" @click="doDelete(item._id)">删除</button>

2.添加方法

  1. methods:{
  2. doDelete(id){
  3. console.log(id)
  4. this.movies = this.movies.filter(item=>item._id != id);
  5. //更新数据
  6. $.ajax({
  7. url:"http://localhost:8080/doDelete",
  8. method:"post",
  9. data:{
  10. id
  11. }
  12. }).then(res=>{
  13. console.log(res)
  14. })
  15. }
  16. }

3.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. })