recaptcha模型是空白的vue.js

时间:2018-03-19 01:56:25

标签: vue.js laravel-5.6

问题

loginForm.recaptcha始终为空。我错过了什么吗?

组件

<template>
    <div>
        <vue-recaptcha  v-model="loginForm.recaptcha"
            sitekey="My key">
        </vue-recaptcha>
    </div>
</template>

<script>
    export default {
        data() {
            return { 
                loginForm: {
                    recaptcha: ''
                }
            }
        }
    }
</script>

app.js

import VueRecaptcha from 'vue-recaptcha';
Vue.use(VeeValidate);
Vue.component('vue-recaptcha', VueRecaptcha);

我可以确认验证码是否成功呈现。

1 个答案:

答案 0 :(得分:0)

vue-recaptcha没有value / v-model属性。您可以使用verify事件:

请参阅demo JSFiddle here

代码:

Vue.component('vue-recaptcha', VueRecaptcha);

new Vue({
  el: '#app',
  data: {
    loginForm: {
      recaptcha: ''
    }
  },
  methods: {
    recaptchaVerified(response) {
     this.loginForm.recaptcha = response;
    }
  }
})
<script src="https://www.google.com/recaptcha/api.js?onload=vueRecaptchaApiLoaded&render=explicit" async defer>
</script>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-recaptcha@latest/dist/vue-recaptcha.js"></script>

<div id="app">
   <div>
        <vue-recaptcha @verify="recaptchaVerified"
            sitekey="your key">
        </vue-recaptcha>
    </div>
   loginForm: {{ loginForm }}
</div>