現在的函數const index1 = JSON.stringify(this.selectGame).indexOf(JSON.stringify(item1));
???下面要怎么寫,如果點擊時對象數組this.selectGame中包含有對象item1,就刪除當前點擊的對象之前的函數 //點擊選擇收藏的內容
check_show(item1) {
const index1 = this.selectGame.indexOf(item1); // let aa = { idName:item.Id,nameId:item.Name}
if(index1 > -1 ){ this.selectGame.splice(index1, 1)
}else if(this.selectGame.length < 10){ this.selectGame.push(item1);
}
},上面的函數在 this.selectGame.push(item1);執行中添加進的元素有效,如果是selectGame中途就已經包含有元素,就不能起作用于是我用JSON.stringify將item1都轉成了字符串,但是問題是indexOf出來的結果是字符串的長度,像是317,175,818,2500之類的,就不能用this.selectGame.splice(index1, 1)將包含有的函數按照位置刪除
vue 數值對象和對象 indexOf()問題
慕田峪9158850
2018-11-13 12:53:09