在vue.js的應用程序,我有這個部分,與無限的分頁取數據涉及:如何打破axios承諾與條件?
fetchData() {
this.loading = true
this.page++;
axios.get(this.BASE_URL + '/api/jokes/'+'?page='+this.page).then(response =>
this.jokes = response.data)
.then(if (this.jokes.length == null) {throw new Error("end of pagination")})
.catch(function (error) {
});
document.body.scrollTop = document.documentElement.scrollTop = 0;
this.loading = false;
};
我想停止渲染空jokes
,打破了該功能的響應是否爲空。正如你可以在代碼abouve看,我把其他有條件的話,但對if
得到錯誤:
Module build failed: SyntaxError: Unexpected token (169:20)
所以我不知道什麼是實現這一目標的正確方法是什麼?
在'then'回調中添加括號'{}'。 – alexmac
@alexmac能詳細說明一下嗎?我是新來的js的東西。 – Karlom
你在if語句周圍沒有函數表達式。 – Bergi