javascript - 在 VUE 中显示 JSON 字符串数组
问题描述
我有一个要获取的 JSON 数据,但在前面显示一个数组时遇到问题。
所以目前我得到这个输出:
Id: 1
name: Adam
Factors: ["One","Two"]
我希望它像这样显示:
Id: 1
name: Adam
Factors: One Two
这就是我的 JSON 的样子:
{
"credits": [
{
"id": 1,
"name": "Adam",
"Factors" : ["One", "Two", "Three"]
},
{
"id": 2,
"name": "Jonas",
"Factors" : ["One", "Two", "Three"]
}
]
}
这是我在 VUE 中的前端代码:
获取数据:
export default {
name: 'app',
data(){
return{
isOpen: false,
id: '',
credits: []
}
},
mounted() {
this.search()
},
methods: {
search() {
if(this.id!="") {
axios
.get(`http://localhost:5041/credits/`, {
params: {
...this.id && {id: this.id}
}
})
.then(response => {
this.credits = response.data
})
}
}
我的 div 显示信息:
<div v-show="isOpen">
<p>Credit ID: {{credits.id}}</p>
<p>Client: {{credits.name}}</p>
<p>DE Factors: <li>{{credits.Factors}}</li></p>
</div>
那么,如何访问确切帖子的所有数组元素?这就是我要展示的内容: Factors: ["One","Two"] 这就是我想要展示的内容: Factors : One Two
解决方案
您可以使用Array.join()
<div v-show="isOpen">
<p>Credit ID: {{ credits.id }}</p>
<p>Client: {{ credits.name }}</p>
<p>DE Factors: {{ credits.Factors.join(' ') }}</p>
</div>
推荐阅读
- wpf - 我们如何在 WPF 中数据网格的最后一行设置滚动条
- c# - Angular 发布请求 Cors 问题
- javascript - 将 req.body 属性映射到对象键
- javascript - Cheerio 不返回动态添加的内容
- r - 在ggplot2中循环变量
- mysql - 对于给定的一组数据,如何检查输入是否包含整组数据?
- scala - 超时后停止 fs2-stream
- sql-server - 如何将数据从elasticsearch导入sql server数据库?
- ios - 如何在 Core Data 的 NSFetchedResultsController 中使用缓存
- c# - C# Web 应用程序剃须刀页面 - 编辑集合时如何克服 IndexOutOfRange 异常?