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