<template>
 <div id="app">
  <Cascader :options.sync="options" v-model="value" :lazyload="lazyload"></Cascader>
  <Hello></Hello>
 </div>
</template>
<script>
import dataList from './data.json';
import Cascader from './components/Cascader';
import Hello from './components/Hello'
const fetchData = pid => new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve(dataList.filter(item => item.pid == pid));
  }, 1000);
});

export default {
  methods: {
    async lazyload(id, callback) {
      const children = await fetchData(id);
      callback(children);
    },
    //   async change(value) {
    //       let lastItem = value[value.length-1];
    //       let id = lastItem.id;
    //       let children = await fetchData(id);
    //       this.$set(lastItem,'children',children)
    //   }
  },
  async mounted() {
    const data = await fetchData(0);
    this.options = data;
  },
  data() {
    return {
      value: [],
      options: [],
    };
  },
  components: {
    Cascader,
    Hello
  },
};
</script>
