createObjectURL获取图片验证码的url

// 获取 captchaCode、captchakey
globalData.getCaptchaKey=function(){
  return new Promise((resolve,reject)=>{
    let urlRaw ='https://pet.sonystyle.com.cn/eSolverOmniChannel/account/displayCaptcha.do';
    axios({
      method: 'GET',
      url: urlRaw+'?'+Date.now(),
      responseType: "blob",
    })
      .then((res)=>{
        this.captcha.captchaCode=URL.createObjectURL(res.data);
        this.captcha.captchakey=res.headers.captchakey;
        resolve(res);
      })
      .catch((error) => {
        console.log("captchakey:",error);
      });
  });

};

<div class="validimg">
  <img :src="captcha.captchakey"
</div>




例2:

<div class="validimg">
  <img :src="validimgSrc">
</div>

globalData.getVerificationCode=function(){
  const src = API.member.displayCaptcha();
  return src+'?stamp='+Date.now();
}

调用:

getVerificationCode(){
  let imgSrc=global.globalData.getVerificationCode();
  this.validimgSrc = imgSrc;
}

猜你喜欢

转载自blog.csdn.net/pansuyong/article/details/80924502
今日推荐