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);
        }
      });

    });




  },

 

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

猜你喜欢

转载自www.cnblogs.com/fps2tao/p/12964000.html