猿问

一个数组里包裹一个很多个对象,点击对象往另一个数组里添加,如何避免重复添加

            arr1: [
                {
                    id: 1,
                    right: true,
                    rightName: "对的",
                    wrong: false,
                    wrongName: "错的"
                },
                {
                    id: 2,
                    right: true,
                    rightName: "对的",
                    wrong: false,
                    wrongName: "错的"
                },
                {
                    id: 3,
                    right: true,
                    rightName: "对的",
                    wrong: false,
                    wrongName: "错的"
                }
            ],
            arr2: []
                <li v-for="item in arr1" :key="item.id" @click="addToArr2(item)">
                    <div>
                        <input type="checkbox" v-model="item.right">
                        <span>{{item.rightName}}</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="checkbox" v-model="item.wrong">
                        <span>{{item.wrongName}}</span>
                    </div>
                    <hr>
                </li>
        addToArr2(item){
            this.arr2.push(item)
        }
慕哥9229398
浏览 922回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答