参考文章一:文章地址
async getScheduleList(selectDate) {
let response;
// 这里request为向服务的发请求的方法
await request(api.getScheduleList, {
date: selectDate
}).then(res => {
response = res;
});
return response
}
init() {
this.getScheduleList(selectDate).then(res => {
console.log(res)
})
}
参考文章二:文章地址
data() {
return {
topicList: []
}
},
async created() {
await this.getTopicList()
console.log(this.topicList)
},
methods: {
async getTopicList() {
let resp = await axios.get(`/topic`)
if (resp.data.status === 1) {
this.topicList = resp.data.data.data
}
}
}

这两篇博客展示了在JavaScript中如何异步获取数据。第一篇博客详细介绍了使用await关键字配合request方法获取scheduleList的过程,并在init函数中调用该方法进行数据加载。第二篇博客则是在Vue环境中,通过axios获取topicList,数据加载完成后更新组件状态。两篇文章都涵盖了异步操作和数据初始化的关键步骤。
5823

被折叠的 条评论
为什么被折叠?



