【发布时间】:2018-07-30 12:58:54
【问题描述】:
我正在加载来自 .json 的数据,但 v-for 不返回循环。
我的 HTML:
<div id="app">
<template v-for="product in products">
<p>{{ product.brand }}</p>
<p>{{ product.images }}</p>
<p>{{ product.id }}</p>
<p>{{ product.title }}</p>
<p>{{ product.description }}</p>
<p>{{ product.price }}</p>
</template>
</div>
我的 JS:
new Vue({
el: '#app',
data: {
products: []
},
methods: {
},
created: function() {
var self = this;
self.$http.get('http://localhost/app/products.json').then(function(response) {
self.products = response.body;
});
}
});
我的 JSON:
"product": [
{
"brand": "Apple",
"images":"images/iphone-x-64-gb.jpg",
"id": "iphone-x-64-gb",
"title": "iPhone X 64 GB",
"description": "Lorem ipsum dolor",
"price": "1.159,00"
},
{
"brand": "Apple",
"images":"images/iphone-x-256-gb.jpg",
"id": "iphone-x-256-gb",
"title": "iPhone X 256 GB",
"description": "Lorem ipsum dolor",
"price": "1.329,00"
},
{
"brand": "Apple",
"images":"images/iphone-8-64-gb.jpg",
"id": "iphone-8-64-gb",
"title": "iPhone 8 64 GB",
"description": "Lorem ipsum dolor.",
"price": "819,99"
}
]
}
如果我像这样用 HTML 编写它是行不通的,但如果我把
{{ product[3].brand }}
例如...我只能看到这个,只是循环不起作用。【问题讨论】: