【ApiCode】切换element标签页组件时重新生成验证码

这里主要利用了 &key=${ this.refreshCode },然后在切换标签页时会将 refreshCode赋值为 true ,为true时 &key=${ this.refreshCode } 条件会触发Date.now() 生成当前时间  ,会重新生成验证码
 

<template>
  <el-tabs @tab-click="handleClick">
    <el-tab-pane label="用户登录" name="first">
      <div class="grid-content bg-purple-dark">
          <img :src="RandomVerificationCode" alt="" />
      </div>
    </el-tab-pane>
    <el-tab-pane label="商家登录" name="second">
      <div class="grid-content bg-purple-dark">
          <img :src="RandomVerificationCode" alt="" />
      </div>
    </el-tab-pane>
  </el-tabs>
</template>  

  data () {
    return {
      refreshCode: false
    }
  },

computed: {
    RandomVerificationCode () {
      return `/api_proxy/recycle/captcha?r=${Math.random()}&key=${
        this.refreshCode ? Date.now() : ''
      }`
    }
  },

methods: {
 // 标签页切换时触发
   handleClick(tab, event) {
    this.refreshCode = !this.refreshCode;
  }
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sorry, as an AI language model, I am not able to generate a Vue Element-based login verification code page. However, I can provide you with some guidance on how to create one: 1. Install Vue.js and Vue Element libraries: ``` npm install vue npm install element-ui ``` 2. Create a Vue component for the login form: ``` <template> <div> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left"> <el-form-item label="Username" prop="username"> <el-input v-model="loginForm.username"></el-input> </el-form-item> <el-form-item label="Password" prop="password"> <el-input type="password" v-model="loginForm.password"></el-input> </el-form-item> <el-form-item label="Verification Code" prop="verificationCode"> <el-input v-model="loginForm.verificationCode"></el-input> <img :src="verificationCode" @click="changeVerificationCode" style="cursor: pointer;"> </el-form-item> <el-form-item> <el-button type="primary" @click="submitLoginForm">Login</el-button> </el-form-item> </el-form> </div> </template> <script> export default { data() { return { loginForm: { username: '', password: '', verificationCode: '' }, loginRules: { username: [{ required: true, message: 'Please input your username', trigger: 'blur' }], password: [{ required: true, message: 'Please input your password', trigger: 'blur' }], verificationCode: [{ required: true, message: 'Please input the verification code', trigger: 'blur' }] }, verificationCode: '' } }, methods: { changeVerificationCode() { // generate and set a new verification code image this.verificationCode = 'http://your-server/api/generate-verification-code-image?timestamp=' + Date.now() }, submitLoginForm() { // submit the login form to the server for authentication this.$refs.loginForm.validate(valid => { if (valid) { // form is valid, proceed with the login // ... } else { // form is invalid, do nothing } }) } }, mounted() { // generate and set the initial verification code image this.changeVerificationCode() } } </script> ``` 3. Create a server API for generating the verification code image: ``` const express = require('express') const app = express() app.get('/api/generate-verification-code-image', (req, res) => { // generate a verification code image and return it as a response // ... }) app.listen(3000, () => { console.log('Server started on port 3000') }) ``` 4. Configure the server API URL in the Vue component: ``` export default { data() { return { verificationCode: 'http://your-server/api/generate-verification-code-image?timestamp=' + Date.now() } }, methods: { changeVerificationCode() { this.verificationCode = 'http://your-server/api/generate-verification-code-image?timestamp=' + Date.now() } } } ``` 5. Style the login form using CSS: ``` <style> .el-form-item__label { font-size: 16px; } .el-button { margin-top: 20px; } </style> ``` 6. Use the login form component in your Vue app: ``` <template> <div> <login-form></login-form> </div> </template> <script> import LoginForm from './components/LoginForm.vue' export default { components: { LoginForm } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值