输入框和图片的vue.js代码
<!--图片-->
<el-form-item >
<el-col :span="12">
<!--输入图片验证码-->
<el-form-item prop="captcha">
<el-input type="test" v-model="loginForm.captcha" auto-complete="off" placeholder="验证码, 单击图片刷新"
style="width: 100%;">
</el-input>
</el-form-item>
</el-col>
<el-col class="line" :span="1"> </el-col>
<el-col :span="11">
<!--图片-->
<el-form-item>
<img style="width: 100%;" class="pointer" :src="loginForm.src" @click="refreshCaptcha">
</el-form-item>
</el-col>
</el-form-item>
在
data(){
loginForm:{
userid:'admin',
password:'123',
captcha:'',
src:''
},
}
methods:{
refreshCaptcha(){
this.$http.get('/Captcha.jpg',{
responseType: 'arraybuffer',
})
.then(response => {
return 'data:image/png;base64,' + btoa(
new Uint8Array(response.data)
.reduce((data, byte) => data + String.fromCharCode(byte), '')
);
}).then(data => {
this.loginForm.src = data
})
console.log(this.loginForm.src)
},
}
mounted(){
this.refreshCaptcha()
}
图片