load json and show in #each block; Uncaught Error: {#each} only iterates over array-like objects
load json and show in #each block; Uncaught Error: {#each} only iterates over array-like objects
在 Svelte (3) 中,我正在通过汇总 json 插件加载 JSON,并尝试在模板中执行 #each 循环
App.svelte
<script>
import * as quests from './quests.json';
</script>
<main>
<h1>DDO Hardcore Favor Planner</h1>
{#each quests as quest}
{quest.name}
{/each}
</main>
我正在
Uncaught Error: {#each} only iterates over array-like objects.
示例json摘录
[
{
"name": "Violent Delights",
"level": 1,
"pack": "Keep on the Borderlands",
"patron": "The Gatekeepers",
"favor": 2
},
{
"name": "The Hobgoblin Horde",
"level": 1,
"pack": "Keep on the Borderlands",
"patron": "The Gatekeepers",
"favor": 3
}
]
导入错误
而不是
import * as quests from './quests.json';
使用
import quests from './quests.json';
在 Svelte (3) 中,我正在通过汇总 json 插件加载 JSON,并尝试在模板中执行 #each 循环
App.svelte
<script>
import * as quests from './quests.json';
</script>
<main>
<h1>DDO Hardcore Favor Planner</h1>
{#each quests as quest}
{quest.name}
{/each}
</main>
我正在
Uncaught Error: {#each} only iterates over array-like objects.
示例json摘录
[
{
"name": "Violent Delights",
"level": 1,
"pack": "Keep on the Borderlands",
"patron": "The Gatekeepers",
"favor": 2
},
{
"name": "The Hobgoblin Horde",
"level": 1,
"pack": "Keep on the Borderlands",
"patron": "The Gatekeepers",
"favor": 3
}
]
导入错误
而不是
import * as quests from './quests.json';
使用
import quests from './quests.json';