淺談vue獲得后臺數(shù)據(jù)無法顯示到table上面的坑
因為剛學(xué)vue然后自己自習(xí)了一下axios,然后想寫一個簡單的查詢后臺數(shù)據(jù)
<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) { }) }
然后后臺可以獲取到數(shù)據(jù),但是無法顯示到table上面
發(fā)現(xiàn)this.uList雖然改變的數(shù)據(jù)但是數(shù)據(jù)無法顯示到table上面
然后發(fā)現(xiàn)這里的this不是外部的this對象,然后進行了更改,數(shù)據(jù)就回顯了
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引入的順序不對,導(dǎo)致不能正常顯示vue中的值
正確的順序應(yīng)該是:
先引入vue的js--------html代碼-----最后引入自己寫的js
以上這篇淺談vue獲得后臺數(shù)據(jù)無法顯示到table上面的坑就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. PHP設(shè)計模式中工廠模式深入詳解2. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明3. Ajax實現(xiàn)表格中信息不刷新頁面進行更新數(shù)據(jù)4. JSP數(shù)據(jù)交互實現(xiàn)過程解析5. ThinkPHP5實現(xiàn)JWT Token認證的過程(親測可用)6. .NET中l(wèi)ambda表達式合并問題及解決方法7. ASP.NET MVC遍歷驗證ModelState的錯誤信息8. 解決AJAX返回狀態(tài)200沒有調(diào)用success的問題9. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向10. CSS hack用法案例詳解
