多个请求下 loading 的展示与关闭

data () {
  return {
     loadingCount: 0,
isShowLoading: false
} }

methods: {
  addLoading() {
    this.loadingCount++
    this.isShowLoading = true
  },
  isCloseLoading() {
       this.loadingCount--
       if (this.loadingCount == 0) {
           this.isShowLoading = false
       }
   },
  getData1 () {
    this.addLoading = true
    axios.get('').then(res => {
      this.isCloseLoading()
    }).catch(err => {
      this.loadingCount = 0
      this.isShowLoading = false
    })
  },
 getData2 () {
   this.addLoading = true
   axios.get('').then(res => {
     this.isCloseLoading()
   }).catch(err => {
     this.loadingCount = 0
     this.isShowLoading = false
   })
 }
}
loadingCount
原文地址:https://www.cnblogs.com/zhangrenjie/p/14137675.html