1.绑定事件
<button type="button" class="btn btn-danger" @click="doDelete(item._id)">删除</button>
2.添加方法
methods:{
doDelete(id){
console.log(id)
this.movies = this.movies.filter(item=>item._id != id);
//更新数据
$.ajax({
url:"http://localhost:8080/doDelete",
method:"post",
data:{
id
}
}).then(res=>{
console.log(res)
})
}
}
3.index.js配置路由
//index.js
router.post("/doDelete",async ctx=>{
console.log(ctx.request.body);
var {id} = ctx.request.body;
await Top250Model.remove({_id:id})
})