// 获取 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; }