首先設(shè)置img標(biāo)簽
<img v-bind:src="captchaBase64Img" @click="SetBase64Img" height="60px" width="240px"/>
data()函數(shù)設(shè)置
data() {
return {
captchaBase64Img: ""
};
},
methods函數(shù)
methods: {
// 設(shè)置驗(yàn)證碼圖片
SetBase64Img: function() {
let captchaBase64Url = this.GetServerUrl() + "/captcha";
this.axios
.get(captchaBase64Url)
.then(response => {
this.captchaBase64Img = response.data;
})
.catch(error => {
alert(error);
});
}
}
注意:在寫(xiě)axios部分時(shí)一定要按照上面部分寫(xiě)罗晕,如果寫(xiě)成下面的方式甥捺,肯定會(huì)翻車(chē)
this.axios
.get(captchaBase64Url)
.then(function (response) {
this.captchaBase64Img = response.data;
})
.catch(function(error){
alert(error);
});
mounted函數(shù)
mounted() {
this.SetBase64Img();
},