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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM