Both interfaces such as vue return results before executing the next instance

  • 2021-08-12 01:52:34
  • OfStack

next can only be used once, and can be solved by Promise. all. Wait for the step operation to return to the result before next:


beforeRouteEnter (to, from, next) {
 // Promise.all  Wait until  Promise  All  resolve  Run after (then)
 Promise.all([
  main._base({
   methodName: 'QueryProductInfo',
   productId: to.params.id
  }),
  main._base({
   methodName: 'QueryProductReview',
   type: '0',
   index: '0',
   count: '2',
   productId: to.params.id
  })
 ])
 .then( result => next( vm => {
  //  Row fruits are placed in the above order  result  , so  result[0] , representing the first 1 Letter  resolve  Fruit 
  vm.product = result[0].data.product
  vm.shop = result[0].data.shop

  vm.evalData = result[1].data
 }))
}

Additional knowledge: await async is used to execute interfaces sequentially when multiple interfaces are requested in vue

I won't talk too much, let's just look at the code ~


 async getSelectOrg () {
  console.log('----1')
  return axiosPost('/api/uum/org/orglist', {
   accessToken: localStorage.token,
   option: true}).then(response => {
   this.options_grade = []
   if (response.data.data.length > 1) {
    this.options_grade.push({
     value: '-1',
     label: ' All '
    })
    this.formInline.organization = '-1'
   } else if (response.data.data.length === 1) {
    this.formInline.organization = response.data.data[0].orgCode
   }
   for (let i = 0; i < response.data.data.length; i++) {
    let tmp = {}
    tmp.value = response.data.data[i].orgCode
    tmp.label = response.data.data[i].orgName
    this.options_grade.push(tmp)
   }
   console.log('----2')
  }).catch(err => {
   console.log(err)
  })
 },
 async getSelect () {
  await this.getSelectOrg()
  console.log('----3')
  this.searchInfo()
 }
},
mounted () {
 let that = this
 window.onresize = function () { //  Define window size change notification events 
  // _this.screenWidth = document.documentElement.clientWidth //  Window width 
  that.clientHeight = document.documentElement.clientHeight //  Window height 
 }
 this.getSelect()
},

Related articles: