【发布时间】:2019-06-13 14:51:06
【问题描述】:
我正在尝试通过在模块 (https://hackernoon.com/import-json-into-typescript-8d465beded79) 中导入和迭代 json 来在 nuxt 项目 (Using different text values with vuetify component) 中动态构建 vuetify 组件。
我在 /static/info.json 中的 json 是:
{
"id": 1,
"name": "Johnson, Smith, and Jones Co.",
"amount": 345.33,
"Remark": "Pays on time"
}
在我的 vue 组件中,我有:
import * as data from '../static/info.json';
const word = data.name;
console.log(word); // output 'testing'
console.log(data); // output 'testing'
var jsonData = JSON.parse(data);
// console.log(jsonData); // output 'testing'
行:
var jsonData = JSON.parse(data);
原因:
Cannot convert object to primitive value
如何遍历导入的 json?
【问题讨论】:
-
你是从 json 文件中导出东西吗?
标签: javascript json vue.js vuetify.js nuxt.js