Check to cancel push and splice delete

data:{
    
    
arry:[
    {
    
    
      id:1,
      name:'dada'
    },
    {
    
    
      id:2,
      name:'aaa'
    }
  ]
}
 fanxuan(){
    
    
    let that = this
    let arry = that.data.arry
    let id = '4'//当前选中的id
    let aaa = {
    
    
      id:3,
      name:'woshi3'
    }//当前选中的对象
    for(let i in arry){
    
    
      if(arry[i].id == id){
    
    //判断当前push的有没有重复的,有就反选
        arry.splice(i,1)
        console.log(arry)
        return false
      }
    }
    arry.push(aaa)
    console.log(arry)
  },

Guess you like

Origin blog.csdn.net/hql1024/article/details/106941480