网络编程
位置:首页>> 网络编程>> JavaScript>> 浅谈vue获得后台数据无法显示到table上面的坑

浅谈vue获得后台数据无法显示到table上面的坑

作者:顾南与歌  发布时间:2024-05-13 09:07:16 

标签:vue,后台,数据,table

因为刚学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) {

})
   }
})

补充知识:vue data有值,但是页面{{}} 取不到值

我的问题出在js引入的顺序不对,导致不能正常显示vue中的值

正确的顺序应该是:

先引入vue的js--------html代码-----最后引入自己写的js

来源:https://blog.csdn.net/qq_40421610/article/details/83587591

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com