vue删除指定id的数据


 

注意click需要传入当前的id值

deletes:function(id){
this.$http.delete("http://jsonplaceholder.typicode.com/users/"+id).
then(function(data){
console.log(data)
this.$router.push({path:"/",query:{alert:"用户删除成功"}})

})

上面是接口

this.list.some((item,i)=>{
if(item.id==val){
this.list.splice(i,1)
/// some循环如果true,就会终止后续循环
return true;
}

})

也可以用some函数,第一个参数是这个数组,第二个是索引值

 

 

调用接口删除ID的数据axios

remove(id){
console.log(id);
axios({
method:"get",
url:'http://jsonplaceholder.typicode.com/users',
params:{
id:id
}
}).then((data) =>{
if(data.status===200){
console.log(data)
//删除成功再次调用列表借口
this.load()
}else{
//删除失败
}


})

},

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM