[英]Cannot convert object to primitive value with imported json
I'm trying to dynamically build a vuetify component in a nuxt project ( Using different text values with vuetify component ) by importing and iterating through json in a module (https://hackernoon.com/import-json-into-typescript-8d465beded79 ).我试图动态构建一个nuxt项目vuetify组件( 使用与vuetify成分不同的文本值由模块在进口和迭代通过JSON()https://hackernoon.com/import-json-into-typescript-8d465beded79 )。
My json in /static/info.json is:我在 /static/info.json 中的 json 是:
{
"id": 1,
"name": "Johnson, Smith, and Jones Co.",
"amount": 345.33,
"Remark": "Pays on time"
}
In my vue component I have:在我的 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'
The line:线路:
var jsonData = JSON.parse(data);
causes:原因:
Cannot convert object to primitive value
How can I iterate through the imported json?如何遍历导入的 json?
I would guess data is already an object and doesn't need to be parsed again.我猜数据已经是一个对象,不需要再次解析。 The import has turned it into an object.
导入已经把它变成了一个对象。 You've already used it with data.name
您已经将它与 data.name 一起使用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.