【发布时间】:2022-11-16 07:04:41
【问题描述】:
我试图在模板中显示一个非常简单的数组。我不明白为什么这不起作用。
我通过 try/catch 语句获取数据。数据是 JSON,里面有一个数组,所以我想这说明它是多级数组。
常量在console.log 中正确显示,但在模板中不正确。
尝试显示数据
<template>
<!-- This doesn't return anything -->
{{modules}}
<!-- Neither does this -->
<span v-for="(item, index) in modules" :key="index">{{item}}</a>
<!-- This works as it should -->
<li v-for="company in companies" :key="companies.company_name">
{{ company.company_name }}
{{ company.app_modules }}
<pre>{{ company }}</pre>
</li>
</template>
获取数据
const companies = ref([])
try {
// Await and get the data
companies.value = data
const modules = data[0].app_modules
// This logs the array
console.log(modules)
} catch (e) {
console.error(e)
}
“模块”数组就是这么简单
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
]
【问题讨论】:
-
您没有
<script>标签。 -
先学习 Vue 3 再学习 Nuxt3 你缺乏 Vue 3 的基础知识。
-
这里的
companies是什么?你在等什么?你在你的 Vue 开发工具中看到了什么?请提供minimal reproducible example。