ES6语法异步转同步(小程序中测试)

 

 

  /**
   * 
   * 
   */
  test: async function(){
    let that = this;

    console.log(1);
    await  that.getCanvasImg().then(function(res){
      console.log(res);
      console.log(2);
    });
    console.log(3);
    await  that.getCanvasImg().then(function(res){
      console.log(res);
      console.log(4);
    });
    console.log(5);


  },
  /**
   * 获得canvas中的临时图片地址
   */
  getCanvasImg: function(res){
    return new Promise((resolve,reject)=>{
      let imgPath = "";
      wx.canvasToTempFilePath({
        width: 90,
        height: 90,
        destWidth: 150,
        destHeight: 150,
        canvasId: 'canvas_wx',
        success(res) {
          //console.log(res.tempFilePath);
          imgPath = res.tempFilePath;
          resolve(imgPath);
        },
        fail(res){
          reject(false);
        }
      });

    });




  },

 

 

 ES6语法异步转同步(小程序中测试)_第1张图片

 

 

 

 

参考 : https://www.jianshu.com/p/c1b629d104ac

 

你可能感兴趣的:(ES6语法异步转同步(小程序中测试))