vue 根据数组值删除元素(存在删除,不存在添加)
作者:互联网
<template> <view v-for="(item, index) in dataList" :key="index"> <view class="memberBox" @click="handleTouch(item, index)">{{index}}</view> </view> </template> <script> export default { data(){ dataList:[] } methods: { handleTouch(item,index){ let arr = [1,2,3,4,5,6,7,8,9]; let arr2 = []; let indexs = arr.findIndex((items) => items == 1); if(indexs==-1){ arr2.push(item,id) }else{ arr2.splice(arr2.indexOf(item.id),1) } } } } </script>
标签:存在,vue,删除,arr,item,let,arr2,indexs,id 来源: https://www.cnblogs.com/james-L/p/15757281.html