處理頁面多個接口自上而下請求順序

if(_this.centerName.length>2){//多於兩個時
  new Promise((resolve, reject) => {
    if(_this.centerName[0]=='專題'){
        _this.specialFun()
    }else{
		_this[_this.centerFun[_this.centerName.indexOf(_this.centerName[0])]]()
	}
	if(_this.centerName[1]=='專題'){
		_this.specialFun()
	}else{
		_this[_this.centerFun[_this.centerName.indexOf(_this.centerName[1])]]()
	}
	resolve(res)
}).then(res=>{
	for (let index = 2; index < _this.centerFun.length; index++) {
		if(_this.centerFun[index]=='changeSpecial'){
			_this.specialFun()
		}else{
			_this[_this.centerFun[index]]()
		}
	  }
	})
	}else{//少於兩個時 全部加載
		for (let ce_index = 0; ce_index < _this.centerFun.length; ce_index++) {
			if(_this.centerFun[ce_index]=='changeSpecial'){
				_this.specialFun()
			}else{
				_this[_this.centerFun[ce_index]]()
			}
		}
	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章