第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

vue axios請(qǐng)求數(shù)據(jù)問(wèn)題?

vue axios請(qǐng)求數(shù)據(jù)問(wèn)題?

慕桂英3389331 2019-05-21 10:52:17
寫(xiě)了一個(gè)函數(shù)返回?cái)?shù)據(jù),Vue.prototype.$http=axiosVue.prototype.getData=function(url){let_data='';this.$http.get(url).then(res=>{_data=res.data;});return_data;}這樣獲取不到數(shù)據(jù),返回的還是空。不知道怎么解決,或有什么辦法可以對(duì)axios設(shè)置同步。我是想這樣直接獲取數(shù)據(jù)this.list=this.getData(url);或者data的時(shí)候,直接返回?cái)?shù)據(jù)data:function(){returnthis.getData(url);}
查看完整描述

2 回答

?
慕哥9229398

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊

用asyncawait可以達(dá)到局部的同步寫(xiě)法
Vue.prototype.getData=function(url){
returnthis.$http.get(url).then(res=>res.data);
}
//調(diào)用
this.getData('url').then(res=>{
console.log(res)
})
//async
asyncfunction(){
vardata=awaitthis.getData(url);
console.log(data);
}
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

不用同步。。。可以這樣定義
Vue.prototype.getData=function(url){
returnaxios.get(url).then(res=>{
returnres.data
});
}
應(yīng)用
this.getData(url).then(data=>console.log(data))
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
  • 2 回答
  • 0 關(guān)注
  • 687 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)