1.绑定事件
<img :src="item.like?'./images/zanhou.png':'./images/zanqian.png'" alt=""
@click="handleClick(item._id)"/></td>
2.方法
handleClick(id){
var movies=this.movies;
var item=movies.find(item=>item._id==id);
if(item.like){
item.like=false;
}else{
item.like=true;
}
this.movies=movies;
$.ajax({
url:"http://localhost:8080/doLike",
method:"post",
data:{
id,
like:item.like
}
}).then(res=>{
console.log(res);
})
}
3.添加
4.处理点赞路由
router.post("/doLike",async ctx=>{
console.log(ctx.request.body);
var{id,like}=ctx.request.body;
await Top250Model.updateOne({_id:id},{$set:{like:like}})
})