<template>
  <a-tree
    :show-line="true"
    :show-icon="true"
    v-on="listeners"
    :replace-fields="replaceFields"
    :tree-data="treeData"
    v-bind="$attrs"
  >
  </a-tree>
</template>

<script>
export default {
  name: "CmsTree",
  props: {
    replaceFields: {
      type: Object,
      default: () => {
        return { children: "children", title: "title", key: "key" };
      },
    },
    requestCall: {
      type: [Array, Function, Object],
      default: () => {
        return [];
      },
    },
  },
  data() {
    let { ...listeners } = this.$listeners;
    return {
      treeData: [],
      listeners: listeners,
    };
  },
  created() {
    this.initDataSource();
  },
  methods: {
    initDataSource() {
      this.requestCall({}).then(({ data }) => {
        this.treeData = data;
      });
    },
  },
};
</script>

<style scoped></style>
