HTML
<el-row>
<el-col :span="15">
<el-form-item prop="code">
<span class="svg-container">
<svg-icon icon-class="validCode" />
</span>
<el-input
v-model="loginForm.code"
auto-complete="off"
placeholder="验证码"
style="width: 50%"
:maxlength="4"
/>
</el-form-item>
</el-col>
<el-col :span="9">
<div class="login-code">
<div v-if="!captchaImage" class="login-code-img" @click="getCaptchaImage()">获取验证码</div>
<img v-else :src="captchaImage" alt="" @click="getCaptchaImage()">
</div>
</el-col>
</el-row>
JS
created() {
this.getCaptchaImage()
},
methods: {
getCaptchaImage() {
// 加随机数防止浏览器缓存验证码图片
var http = 'http://192...'
this.captchaImage = http + '/system/login/captcha?rand = ' + Math.random() * (10 - 0)
}
}