Async/await doesn't work after multi-level calls?


<button open-type="getUserInfo" @getuserinfo="bindGetUserInfo"></button>

export default {
  methods: {
    bindGetUserInfo(e) {
       //  
       this.submitForm()
    },
    submitForm() {
       // 
       this.login()
    },
     async login () {
      wx.login({
        success:async res => {
          let code = res.code;
          if (code) {
            this.submitData["code"] = code

            const data = await Api.Login(this.submitData);  //ajax
            if (data.errcode === 0) {
            //
            }
The ajax request in the

code is defined in the login method. The order of clicking the button call is bindGetUserInfo-> submitForm-> login,await without waiting. I replaced it with

.
export default {
  methods: {
    async bindGetUserInfo(e) {
       //  
       await this.submitForm()
    },
    async submitForm() {
       // 
       await this.login()
    },
     async login () {
      wx.login({
        success:async res => {
          let code = res.code;
          if (code) {
            this.submitData["code"] = code

            const data = await Api.Login(this.submitData);  //ajax
            if (data.errcode === 0) {
            //
            }

this doesn"t work either. I don"t know why?

Jul.01,2021
The method after

await needs to return a promise. Make sure there is no problem with this. Here the login method does not return promise.


   async login () {
    await new Promise((resolve, reject) => {
      wx.login({
        success: res => {
          resolve(res)
        },
        error: err => {
          reject(err)
        }
      })
    })
  }
Menu