[英]Error when trying to retrieve value from a property of a nested object using VueJS Interpolation
I'm having trouble displaying an array inside of an array in Vue JS. 我在Vue JS中无法在数组内部显示数组。 This is my JSON:
这是我的JSON:
{
"id": 1,
"slug": "test-page",
"banner": {
"title": "banner title",
"subTitle": "my sub title",
"hasSubTitle": false,
"hasClass": "jumbotron-houses jumbotron-page"
},
"pageTitle": "Test Page",
"pageDescription": "My Page Description",
"content": "<h1>test</h1>"
}
I'd like to show the banner Title and each individual banner elements. 我想展示横幅标题和每个横幅元素。 I've tried:
我试过了:
{{ page.banner['title'] }}
What am I missing? 我想念什么? This doesn't work?
这行不通吗?
Also tried: 还尝试了:
{{ page.banner[0] }}
Thanks! 谢谢!
banner
is not an array. banner
不是数组。
Try this instead: 尝试以下方法:
{{ page.banner.title }}
demo 演示
var page = { "id": 1, "slug": "test-page", "banner": { "title": "banner title", "subTitle": "my sub title", "hasSubTitle": false, "hasClass": "jumbotron-houses jumbotron-page" }, "pageTitle": "Test Page", "pageDescription": "My Page Description", "content": "<h1>test</h1>" }; document.body.innerText = page.banner.title;
You should check how many objects you received from your Api call. 您应该检查从Api呼叫中收到了多少个对象。 If there is more than one you must use a v-for for each of them or if there is only one you must use
如果有多个,则必须为每个使用v-for,或者,如果必须仅使用一个
{{ page[0].banner.title }}
Also check the name page if it is currect. 还要检查名称页是否正确。
var page = [{ "id": 1, "slug": "test-page", "banner": { "title": "banner title", "subTitle": "my sub title", "hasSubTitle": false, "hasClass": "jumbotron-houses jumbotron-page" }, "pageTitle": "Test Page", "pageDescription": "My Page Description", "content": "<h1>test</h1>" }, ]; document.body.innerText = page[0].banner.title;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.