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
1. The relationship between fonts and character d...
How to introduce svg icons in Vue Method 1 of int...
MariaDB is installed by default in CentOS, which ...
** Install mysql-8.0.20 under Linux ** Environmen...
Solution to MySql service disappearance for unkno...
In some interview experiences, you can often see ...
Today I will take you through the history of ext4...
I recently used Docker to upgrade a project. I ha...
The version of vsCode has been updated in recent ...
Special symbols Named Entities Decimal encoding S...
First, you need to download and install Navicat f...
I believe that many friends who are new to web pag...
Under Linux, if you download and install an appli...
0x00 Introduction A few months ago, I found a vul...
Frameset pages are somewhat different from ordina...