vue获得后台数据无法显示到table上面的坑
因为刚学vue然后自己自习了一下axios,然后想写一个简单的查询后台数据<tr v-for=" user in uList"><td>{{user.id}}</td><td>{{user.name}}</td><td&
·
因为刚学vue然后自己自习了一下axios,然后想写一个简单的查询后台数据
<tr v-for=" user in uList">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.gender}}</td>
</td>
</tr>
然后先是写了这样一个代码
created: function () {
axios.get("http://localhost:8080/student/findAll").then(function (response) {
this.uList = response.data;
console.log(uList);
}).catch(function (reason) {
})
}
然后后台可以获取到数据,但是无法显示到table上面
发现this.uList虽然改变了数据但是数据无法显示到table上面
然后发现这里的this不是外部的this对象,然后进行了更改,数据就回显了
new Vue({
el:'#app',
data:{
uList:[],
},
created: function () {
var arr = this;
axios.get("http://localhost:8080/student/findAll").then(function (response) {
arr.uList = response.data;
console.log(uList);
}).catch(function (reason) {
})
}
})
更多推荐



所有评论(0)