修改新闻模板news-page.nvue中加载数据的请求为async await。
代码在附件。
问题:导致在IOS端await后面的赋值不更新视图。
news-page.nvue
async loadData(refresh) {
if (this.isLoading) {
return;
}
this.isLoading = true;
this.isNoData = false;
var startTime = new Date();
const [err, result] = await uni.request({
url: 'https://unidemo.dcloud.net.cn/api/news',
});
// ------------------------------------------------------------------------
var endTime = new Date();
console.log("request time " + new Date(endTime - startTime).getTime());
const data = result.data;
this.isNoData = (data.length <= 0);
const data_list = data.map((news) => {
return {
id: this.newGuid() + news.id,
newsid: news.id,
article_type: 1,
datetime: friendlyDate(new Date(news.published_at.replace(/\-/g,
'/')).getTime()),
title: news.title,
image_url: news.cover,
source: news.author_name,
comment_count: news.comments_count,
post_id: news.post_id
};
});
if (refresh) {
this.dataList = data_list;
this.requestParams.minId = 0;
} else {
this.dataList = this.dataList.concat(data_list);
this.requestParams.minId = data[data.length - 1].id;
}
this.isLoading = false;
if (refresh) {
this.refreshing = false;
this.refreshFlag = false;
this.refreshText = "已刷新";
if (this.pullTimer) {
clearTimeout(this.pullTimer);
}
this.pullTimer = setTimeout(() => {
this.pulling = false;
}, 1000);
}
},