In our recent project, we need to use Google robot verification. The most important thing for this is to have a VPN, and we also need a Google account applied for by the company (it is useless to apply for it yourself) for commercial use. Use this account to apply for a secret key, and then once you have the secret key, you can do it. 1. First of all, it is the Google robot verification component that I encapsulated: <template> <div ref="grecaptcha"> </div> <!-- <div id="robot"></div> --> </template> <script src="http://www.recaptcha.net/recaptcha/api.js?οnlοad=ReCaptchaLoaded&render=explicit&hl=en" async defer></script> <script> export default { props: ["sitekey"], // The secret key to be transferred mounted() { window.ReCaptchaLoaded = this.loaded; var script = document.createElement("script"); script.src = "https://recaptcha.net/recaptcha/api.js?οnlοad=ReCaptchaLoaded&render=explicit"; document.head.appendChild(script); }, methods: { loaded() { window.grecaptcha.render(this.$refs.grecaptcha, { sitekey: this.sitekey, /** * res returns the verification status of Google. * Return string if successful * No string is returned if failed * So the verification status is determined based on the string */ callback: res => {// true - validation successful// false - validation failedres.length > 0 ? this.$emit("getValidateCode", false) : his.$emit("getValidateCode", true) } }); // grecaptcha.render('robot', { // sitekey: this.sitekey, // /** // * res returns the verification status of Google. // * Return string if successful// * Do not return string if failed// * So judge the verification status based on the string// */ // theme: 'light', // theme color, light and dark are available // size: 'normal', // size rule, normal and compact are available // callback: res => { // res.length > 0 ? this.$emit("getValidateCode", true) : this.$emit("getValidateCode", false) // // true - authentication succeeded // false - authentication failed // } // }); } }, }; </script> <style> </style> 2. Use where needed: <template> <div> <div class="home-content"> <div class="home-content-img"> <!-- <div class="home-content-imgtop"> --> <img src="../../assets/image/202010_JP NIGHT Store Promotional Materials.002.png" alt=""> <img src="../../assets/image/202010_JP NIGHT Store Promotional Materials.003.png" alt=""> <!-- </div> --> <!-- <div class="home-content-imgbottom"> --> <img src="../../assets/image/202010_JP NIGHT Store Promotional Materials.004.png" alt=""> <img src="../../assets/image/202010_JP NIGHT Store Promotional Materials.005.png" alt=""> <!-- </div> --> </div> <div class="home-content-bottom"> <p> <a href="http://www.jp-night.com/terms.html" rel="external nofollow" >Terms of Use</a> and <a href="http://www.jp-night.com/privacy.html" rel="external nofollow" >Privacy Policy</a> Please agree to this.</p> <div class="content-google"> <google-recaptcha ref="recaptcha" :sitekey="key" @getValidateCode='getValidateCode' v-model="validateCode"></google-recaptcha> </div> <div class="login"> <button :class="isNext ?'login-botton-background':'login-botton'" :disabled="isNext" @click="login()">Shop announcement</button> </div> </div> </div> </div> </template> <script> import GoogleRecaptcha from '../../common/module/GoogleRecaptcha' export default { data() { var checkCode = (rule, value, callback) => { if (value == false) { callback(new Error('Please perform human-machine verification')); } else { callback(); } }; return { key: '6Ld9xxgaAAAAAI4xn7seMCmqbxIpVsJ_dwrZu9z1', validateCode: false, isNext:false }; }, created(){ }, mounted(){ }, components:{ Google Recaptcha }, methods:{ login(){ sessionStorage.setItem('token',true) this.$router.push({ path: "/shops", query: { out: true } }) }, getValidateCode(value) { console.log(value); this.isNext = value }, } }; </script> <style lang="scss" scoped> @import "./css/pc.css"; @import "./css/ipad.css"; @import "./css/phone.css"; #rc-anchor-container { width: 335px; } </style> 3. That’s it, the Google robot is ready to use. Schematic diagram: This is the end of this article about the implementation example of vue using Google Recaptcha verification. For more relevant vue Google Recaptcha verification content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of basic knowledge and operations of MySQL database
>>: Use nginx + secondary domain name + https support
Preface In the process of writing code, we will i...
Problem Description After installing the plugin E...
1. Introduction Git is a free, open source distri...
1. Download the mysql-5.7.17-winx64.zip installat...
We know that when using HTML on NetEase Blog, we ...
This article is just to commemorate those CSS que...
During this period of time, I was studying docker...
Table of contents iview-admin2.0 built-in permiss...
1. CSS realizes fixed width on the left and adapt...
When using MySQL to run certain statements, a dea...
Introduction The mysql-utilities toolset is a col...
The functions of the three attributes flex-grow, ...
What is NFS? network file system A method or mech...
If you want to install some 64-bit applications (...
Find the containerID of tomcat and enter the toma...