js请求后端前端代码会不会阻塞呢(等待后端返回数据后再往下执行)
日期: 2021-05-07 分类: 个人收藏 521次阅读
getList() {
this.listLoading = true
this.getDepartmentTree()
sysApi.getPageList(this.listQuery).then(response => {
debugger
let records = response.data.records
this.list = []
// 此法效率比较低
for (let record of records) {
if(record.createBy == this.$store.state.user.userName && record.delFlag == 0){
console.log(this.treeSelectData)
debugger
for (let key in this.treeSelectData) {
if(this.treeSelectData[key].id == record.makerId ){
record.makerId = this.treeSelectData[key].name
}
}
this.list.push(record)
}
}
this.total = this.list.length
this.listLoading = false
});
this.$forceUpdate()
},
说明:
this.getDepartmentTree()会向后端发起请求。
发起请求后,并不一定保证后端已经返回数据的情况下,前端会立即执行sysApi.getPageList及以下代码。
而不是阻塞,等待后端返回数据再去执行sysApi.getPageList
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
下一篇: 编程工作中的回马枪模式
精华推荐