12 props 傳的是數組處理


<template>
  <div>InfoDetailed</div>
</template>
<script>
export default {
  name: "InfoDetailed",
  props: {
    treeData: {
      type: Array,
      required: true
    }
  },
  data() {
    return {};
  },
  methods: {
    handleRemoveConfirm(row) {
      deleteCategory({ categoryId: row.id })
        .then(data => {
          this.$message.success(data.message);
          // 方法1:數組同基本數據類型看待,要顯式通知(update)父組件sync
          // const res= this.treeData.filter(e => e.id !== row.id);
          // this.$emit("update:treeData", res);

          //方法2:實現刪除數組里面特定的項,父組件的值同時被修改(不用通知父組件)
          let index = this.treeData.findIndex(e => e.id === row.id);
          this.treeData.splice(index, 1);
        })
        .catch(err => console.log(err));
    }
  }
};
</script>
<style lang="scss" scoped></style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM