【发布时间】:2018-01-26 13:15:57
【问题描述】:
我的问题在于这个 json。 http://dev-rexolution.pantheonsite.io/api/noticias
我只需要使用 vuejs 2 使用数组的第一个元素才能显示它,使用我工作的控制台但没有 vuejs。
这个控制台日志工作:console.log(response.data[0].title[0].value);
<template>
<div class="Box Box--destacado1">
<div class="Media Media--rev">
<div class="Media-image">
</div>
<div class="Media-body">
<span class="Box-info">{{ noticias[0].field_fecha[0].value}}</span>
<h3 class="Box-title">
<a href="">{{ /*noticias[0].title[0].value */}}</a>
</h3>
<p class="Box-text">{{/*noticias[0].field_resumen[0].value*/}}</p>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
data: () => ({
noticias: [],
errors: []
}),
// Fetches posts when the component is created.
created() {
axios.get(`http://dev-rexolution.pantheonsite.io/api/noticias`)
.then(response => {
// JSON responses are automatically parsed.
this.noticias = response.data
})
.catch(e => {
this.errors.push(e)
})
}
}
</script>
【问题讨论】:
-
“不工作”到底是什么意思?另外,为什么要为您的 URL 使用字符串模板文字?
-
快速浏览浏览器的 Console 和 Network 开发工具应该会发现您可能遇到的任何问题
-
此模板由 Drupal 8 模块 Rest 生成。不起作用,因为它将对象返回为未定义
-
你必须比这更清楚; “将对象返回为未定义” 在哪里?哪段代码导致错误?如果您的网络应用程序在
http://localhost:8080上运行,这应该适合您 -
这段代码在访问 json 元素时不起作用。 {{ noticias[0].field_fecha[0].value}}
标签: javascript json vue.js vuejs2