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