【发布时间】:2018-05-08 11:20:37
【问题描述】:
我是 Vue js 的新手。
我正在尝试使用
将 json 解析到 html 表中<tr v-for="(item) in products">
<td>{{item.id}}</td>
</tr>
但表格打印空行。 如果我尝试打印
<td>{{item}}</td>
然后每行打印json的单个字符。
我的 json : "{id: 'mu'}"
here is the screenshot of the table that prints single character
我错了。拜托,一点指导会有所帮助。
var app4 = new Vue({
el: '#Itemlist',
data: {
products: []
},
mounted: function (){
var self = this;
$.ajax ({
url: "getAll",
method: "GET",
success: function (data) {
self.products = "{id: 'mu'}";
},
error: function(error) {
console.log(error)
}
});
}
})
【问题讨论】:
-
products变量需要是一个数组,所以[{id: 'mu'}]
-
@ChrisDixon 我也试过了,但现在又添加了 2 个空行。
-
您将产品设置为字符串,而不是数组...我将添加答案。