淺談vue獲得后臺(tái)數(shù)據(jù)無法顯示到table上面的坑
因?yàn)閯倢W(xué)vue然后自己自習(xí)了一下axios,然后想寫一個(gè)簡單的查詢后臺(tái)數(shù)據(jù)
<tr v-for=' user in uList'><td>{{user.id}}</td><td>{{user.name}}</td><td>{{user.gender}}</td></td></tr>
然后先是寫了這樣一個(gè)代碼
created: function () { axios.get('http://localhost:8080/student/findAll').then(function (response) { this.uList = response.data;console.log(uList); }).catch(function (reason) { }) }
然后后臺(tái)可以獲取到數(shù)據(jù),但是無法顯示到table上面
發(fā)現(xiàn)this.uList雖然改變的數(shù)據(jù)但是數(shù)據(jù)無法顯示到table上面
然后發(fā)現(xiàn)這里的this不是外部的this對(duì)象,然后進(jìn)行了更改,數(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) { }) }})
補(bǔ)充知識(shí):vue data有值,但是頁面{{}} 取不到值
我的問題出在js引入的順序不對(duì),導(dǎo)致不能正常顯示vue中的值
正確的順序應(yīng)該是:
先引入vue的js--------html代碼-----最后引入自己寫的js
以上這篇淺談vue獲得后臺(tái)數(shù)據(jù)無法顯示到table上面的坑就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. html清除浮動(dòng)的6種方法示例2. JavaScript數(shù)據(jù)類型對(duì)函數(shù)式編程的影響示例解析3. 利用CSS3新特性創(chuàng)建透明邊框三角4. 詳解CSS偽元素的妙用單標(biāo)簽之美5. div的offsetLeft與style.left區(qū)別6. CSS代碼檢查工具stylelint的使用方法詳解7. 使用css實(shí)現(xiàn)全兼容tooltip提示框8. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)9. vue實(shí)現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細(xì)教程10. 不要在HTML中濫用div
