vue 刪除table特定行&表格內容去重

使用filter可以做到去重和刪掉特定行功能

<script>
    export default {
        data(){
            return{
                tableData:[
                    {name:'helen',id:1},
                    {name:'bob',id:2},
                    {name:'helen',id:1},
                ]
            }
        },
          methods(){
            // 去掉重複數據 使用filter去重複數據
            quchong(){
                const res = new Map()
                return tableData.filter(this.tableData=>!res.has(this.tableData.id)&&res.set(this.tableData.id,1))
            }
            // 刪除id爲1的所有條目  使用filter刪除特定行
            shanchu(){
                let tableData1 = tableData.filter(item=>item.id != 1)
            }
        }
    }
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章