Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

shopSum(){
    return new Promise(resolve=>{
      resolve();
      this.$post('ord003', {
        "flag":true
      }).then(res => {
          //请求1 
      })
    })
}
activitySum(){
   return new Promise(resolve=>{
      resolve();
      this.$post('ord003', {
        "flag":true
      }).then(res => {
          //请求2 
      })
    })
}
orderySum(){
   return new Promise(resolve=>{
      resolve();
      this.$post('ord003', {
        "flag":true
      }).then(res => {
          //请求3 
      })
    })
}
shopSum()
.then(activitySum())
.then(orderySum())

这样写他并没有按照顺序 求教


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

首先shopSum、activitySum、orderySum中都要return一个promise,不知道你里面具体是怎么写的
然后像下面这样写

showSum()
.then(activitySum)
.then(ordeySum)

然后好好去学习一下promise,比较推荐mdn的资料,如果有能力尽量去读英文版的,promise本质上是callback的封装,promise学明白了你的问题自然就解决了
https://developer.mozilla.org...
https://developer.mozilla.org...


像这样改

shopSum(){
    return new Promise(resolve=>{
      this.$post('ord003', {
        "flag":true
      }).then(res => {
          resolve();
          //请求1
      })
    });
}

或是更简单一点

shopSum(){
    return this.$post('ord003', {
        "flag":true
      }).then(res => {
          //请求1 
      })
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...