Vuejs 从本地获取数据 json
Vuejs getting data from local json
我在本地文件中得到了一些 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>
您可以将计算作为道具直接传递给 child:
<child :propname="ClearList"></child>
在child中:
export default {
props: ['propname'],
// ...
}
我在本地文件中得到了一些 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>
您可以将计算作为道具直接传递给 child:
<child :propname="ClearList"></child>
在child中:
export default {
props: ['propname'],
// ...
}