Skip to content

Commit f10fbbd

Browse files
committed
fixed readme
1 parent 7812ad9 commit f10fbbd

File tree

1 file changed

+43
-59
lines changed

1 file changed

+43
-59
lines changed

README.md

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,20 @@ The file will be created under js/components/googlerecaptchav3/GoogleReCaptchaV3
364364

365365
### Step 2 Import vue component and Register reCAPTCHA v3 SiteKey
366366

367+
#### A BIG thanks to [@Fluxlicious](https://github.com/Fluxlicious) who improved the vue component.
368+
367369
The Blade way is no longer useful if you use Vue, so we need to manage to assign site key by ourselves. The component supports props below:
368370

369-
Supported: siteKey, elementId, inline and action, check the original file to see the details.
371+
Supported: siteKey, id, inline and action, check the original file to see the details.
370372

371373
````vue
372-
<google-re-captcha-v3
373-
:siteKey="this.siteKey"
374-
:elementId="'contact_us_id'"
375-
:inline="true"
376-
:action="'contact_us'">
377-
</google-re-captcha-v3>
374+
<google-re-captcha-v3
375+
ref="captcha" v-model="gRecaptchaResponse"
376+
:siteKey="'Your Site Key Here'"
377+
:id="'contact_us_id'"
378+
:inline="true"
379+
:action="'contact_us'">
380+
</google-re-captcha-v3>
378381
379382
````
380383

@@ -386,58 +389,52 @@ There are two ways you can bind site key to the component.
386389
````vue
387390
<template>
388391
<div>
389-
<form method="POST" action="/verify">
390-
<div>
391-
<label for="exampleInputEmail1">Email address</label>
392-
<input type="email" id="exampleInputEmail1"
393-
aria-describedby="emailHelp"
394-
placeholder="Enter email">
395-
</div>
392+
<form @submit.prevent="submit">
396393
<div>
397-
<label for="exampleInputPassword1">Password</label>
398-
<input type="password" id="exampleInputPassword1"
399-
placeholder="Password">
394+
<google-re-captcha-v3
395+
ref="captcha" v-model="form.gRecaptchaResponse"
396+
:siteKey="this.siteKey"
397+
:id="'contact_us_id'"
398+
:inline="true"
399+
:action="'contact_us'">
400+
</google-re-captcha-v3>
400401
</div>
401-
<div>
402-
<div id="contact_us_id"></div> // Your reCAPTCHA div element
403-
</div>
404-
405402
<button type="submit">Submit</button>
406403
</form>
407-
<google-re-captcha-v3
408-
:siteKey="this.siteKey"
409-
:elementId="'contact_us_id'"
410-
:inline="true"
411-
:action="'contact_us'">
412-
413-
</google-re-captcha-v3>
414404
</div>
415-
416405
</template>
417406
<script>
418-
import GoogleReCaptchaV3 from '../components/googlerecaptchav3/GoogleReCaptchaV3'; // location might be diff to your case, ensure that your location is right
419-
407+
import GoogleReCaptchaV3 from '../../components/googlerecaptchav3/GoogleReCaptchaV3';
408+
// location might be diff to your case, ensure that your component location is right
409+
420410
export default {
421411
components: {
422412
GoogleReCaptchaV3
423413
},
424414
data() {
425415
return {
426-
siteKey: 'YOUR_SITE_KEY', // provide your site key here
416+
form: {
417+
gRecaptchaResponse: null
418+
},
419+
siteKey: 'Your Site Key',
427420
}
428421
},
429-
created() {
430-
431-
},
432-
computed: {},
433-
mounted() {
434-
435-
},
436-
watch: {},
437-
methods: {}
422+
methods: {
423+
submit() {
424+
axios.post('/verify', this.form).then(
425+
response => {
426+
this.$refs.captcha.execute(); // every time you submit, the reCAPTCHA token needs to be refreshed
427+
}
428+
).catch(
429+
error => {
430+
this.$refs.captcha.execute(); // every time you submit, the reCAPTCHA token needs to be refreshed
431+
});
432+
}
433+
}
438434
}
439435
</script>
440436
437+
441438
````
442439

443440
### or Add site key directly into GoogleReCaptchaV3 component
@@ -447,28 +444,15 @@ Alternatively, I believe most of cases your site key will never be changed, so y
447444
For instance, open published file and find code below:
448445
````vue
449446
....
450-
props: {
451-
siteKey: {
452-
type: String,
453-
required: true
454-
},
455-
.....
456-
},
447+
siteKey: {
448+
type: String,
449+
required: false, // set to true if you don't want to store the siteKey in this component
450+
default: 'Your Site Key Here' // set siteKey here if you want to store it in this component
451+
},
457452
....
458453
459454
````
460455

461-
Remove it from prop and add it in data():
462-
463-
````vue
464-
data() {
465-
return {
466-
siteKey: "YOUR_KEY_HERE",
467-
....
468-
}
469-
},
470-
````
471-
472456

473457
## Advanced Usage <a name="advanced-usage" />
474458

0 commit comments

Comments
 (0)