1

我在本地文件中获取了一些 json 数据,该文件是 .txt 文件,并且无法直接访问数据,因此我只是将文件格式更改为 .json,之后,我尝试使用下面的代码循环获取干净的数据。

我通过在此组件中计算来获取数据,但我想将此干净数据设置为子组件的道具。

我想用干净的数据创建许多子组件。

非常感谢您!

代码:

<script>
 export default {
  name: 'Dashboard',
  components : {
    'my-table': mytable,
    'my-search': search,
  },

  data: function() {
    return {
      casesDataList: [],

    };
  },

  computed:{
    ClearList: function(){
     var casesDataList = this.casesDataList.map(function (neo){
        return {ID: neo.Attributes[1].Value, Date: neo.FormattedValues[0].Value, Owner: neo.FormattedValues[1].Value};
      });
        return casesDataList;
    }
  },

  created: function(){
    this.getCasesData();
  },
  methods: {
    getCasesData() {
      fetch("Weather.json")
      .then(response => response.json())
      .then(data => (this.casesDataList = data.Entities));


    },
  }

};
</script>
4

1 回答 1

1

您可以将计算结果作为道具直接传递给孩子:

<child :propname="ClearList"></child>

在孩子身上:

export default {
    props: ['propname'],
    // ...
}
于 2020-04-10T21:02:18.137 回答