javascript - 如何从 Vue.js 中的 JSON 文件中获取数据?
问题描述
我有具有这种结构的“modified_data.json”JSON 文件。
{
"data": [
[
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
}
],
[
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
}
],
[
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
},
{
"account_id": " "
"account_name": " "
}
]
]
}
我想从每个数组中获取第一个对象的 account_name ...
有没有人可以给我一个解决方案??
现在我使用Vue.js来显示它,我可以用python获取每个数据,但是Vue.js对我来说还不熟悉......请帮助我:)
解决方案
Well, you will have to add the code that you have written for Vue
If you are in a vue app, you can do something like this
<script>
import json from './json/data.json'
export default{
data(){
return{
myJson: json
}
}
}
</script>
and if you are writting it inside an html page. you can do it in 2 steps.
1st is to add the file link as a script
<script src="../file.json"></script>
then in the vue script section you can assign it to the data object.
var ele = new Vue({
el : "#YourElement",
data : ObjName
});
"ObjName" is a name of the json object in the file.
ObjName :
{
"data": [
[
{
"account_id": " "
"account_name": " "
}
推荐阅读
- python - 正则表达式查找所有反斜杠和紧随其后的字符
- java - 我在布局预览中遇到了缺少 CLASSES 的问题
- java - Selenide如何找到SelenideElement的唯一孩子
- java - 如何遍历数据库中的子项并将它们应用于变量
- python - 对于优化表达式,python 2 和 python 3 之间的语义是否存在差异?
- python - Python:将 .txt 文件中的日期时间导入单独的列表
- sql - sql 计数功能无法正常工作
- python - 基于modelPanel设置相机
- javascript - 模板 V 型槽内
在 vue 2.0.15 中不起作用 - sql-server - 传递查询的 from 子句中的语法错误