Had to resort back to good 'ol jQuery, but this is one way to make it work:
// In your vue component asset file
data() {
return {
recaptcha_key: 'your key',
form: new SparkForm({
name: '',
email: '',
grecaptcharesponse: null
})
};
},
methods: {
create() {
// Grab the g-recaptcha-response value via jQuery
this.form.grecaptcharesponse = $('#g-recaptcha-response').val();
Spark.post('/thing/store', this.form)
.then(result=> {
this.form.name = '';
this.form.email = '';
this.form.grecaptcharesponse = null;
grecaptcha.reset();
})
},
},
// in your vue component blade file
<form class="form-horizontal" role="form">
{{ csrf_field() }}
<div class="form-group" :class="{'has-error': form.errors.hasErrors()}">
<!-- Name -->
<div class="row p-b-md">
<div class="col-md-10 col-md-offset-1">
<input type="text" class="form-control" name="name" v-model="form.name" autofocus placeholder="Your Name">
<span class="help-block" v-show="form.errors.has('name')">@{{ form.errors.get('name') }}</span>
</div>
</div>
<!-- Email Address -->
<div class="row p-b-md">
<div class="col-md-10 col-md-offset-1">
<input type="email" class="form-control" name="email" v-model="form.email" placeholder="Your Email Address">
<span class="help-block" v-show="form.errors.has('email')">@{{ form.errors.get('email') }}</span>
</div>
</div>
<!-- reCaptcha -->
<div class="row p-b-md">
<div class="col-md-10 col-md-offset-1">
<div class="g-recaptcha col-md-offset-4" :data-sitekey="recaptcha_key"></div>
<span class="help-block" v-show="form.errors.has('grecaptcharesponse')">@{{ form.errors.get('grecaptcharesponse') }}</span>
</div>
</div>
<!-- Submit Button -->
<div class="row">
<div class="col-md-offset-5 col-md-2">
<button type="submit" class="btn btn-primary"
@click.prevent="create"
:disabled="form.busy">
Submit
</button>
</div>
</div>
</div>
</form>
I had to explicitly call grecaptcha.reset(); after my post is successful since this particular form is in a modal, and without it, a user could open the modal and resubmit without re-verifying the captcha.