tp5与element-admin如何实现登录验证码功能

17 篇文章 1 订阅

tp5验证码如何返回 手册上有
先在vue.config.js设置跨域

     ['/api/system/login/verify']: {
        target: 'http://gq.skyrover.com.cn/api/system/login/verify',
        changeOrigin: true,
        pathRewrite: {
          ['^/api/system/login/verify']: ''
        }
      },

store/user.js

const actions = {
  // user login
  login({ commit }, userInfo) {
    const { name, password,captcha } = userInfo
    return new Promise((resolve, reject) => {
      login({ name: name.trim(), password: password,captcha:captcha }).then(response => {
        console.log('response', response)
        const { data } = response
        commit('SET_TOKEN', data.data)
        setToken(data)
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },

dom

  <el-form-item prop="captcha" style="width: 200px;">
          <el-input ref="verify" v-model="loginForm.captcha" placeholder="验证码" name="verify" type="text" tabindex="1" autocomplete="on" />
          <img id="verify" src="/api/system/login/verify" style="width: 140px;
            height: 44.5px;
            position: absolute;
            margin-left: 50px;" @click="resetVerify"/>
        </el-form-item>
在 methods:下写方法:
    resetVerify(){
      document.getElementById('verify').setAttribute('src','/api/system/login/verify?id='+(((1+Math.random())*0x10000)|0).toString(16))
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值