无法使用导入 json 将对象转换为原始值

Cannot convert object to primitive value with imported json

我正在尝试在 nuxt 项目中动态构建 vuetify 组件 () by importing and iterating through json in a module (https://hackernoon.com/import-json-into-typescript-8d465beded79)。

我在/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?

我猜数据已经是一个对象,不需要再次解析。导入已将其变成一个对象。您已经将它与 data.name

一起使用了