vue 過濾數組數據,可用於控制 el-table 某一行顯示與否

<template>
  <div class="home-addressbook">
    <div class="d-content">
      <el-table :data="tableDataNew" stripe border style="width: 100%">
        <el-table-column prop="name" label="姓名" width="100">
        </el-table-column>
        <el-table-column prop="sex" label="性別" width="80">
        </el-table-column>
        <el-table-column prop="age" label="年齡" width="80">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'home-addressbook',
    components: {},
    data() {
      return {
        tableData: []
      }
    },
    computed: {
      // 使用計算屬性 過濾數組數據
      // 也可以直接在getData中使用 filter 過濾
      tableDataNew: function () {
        return this.tableData.filter((data) => {
          return data.name !== 'admin'
        })
      }
    },
    watch: {},
    methods: {
      getData () {
        this.$get('api接口').then((res) => {
          this.tableData = res.data
        }, error => {
          console.log(error)
        })
      }
    },
    created() {
      this.getData()
    },
    mounted() {
    },
    beforeDestroy() {}
  }
</script>

<style lang='scss' scoped>
  .home-addressbook {
    width: 100%;
    height: 100%;
  }

  .d-header {
    color: white;
  }

</style>

 

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