简体   繁体   English

如何在vue.js的同一组件中添加多个reCaptcha?

[英]How to add multiple reCaptcha in same component in vue.js?

I have a component which contains 2 tabs. 我有一个包含2个标签的组件。 I need to add reCaptcha to both tabs. 我需要将reCaptcha添加到两个选项卡。 I did the following code, but captcha appears only in the first tab 我做了以下代码,但验证码仅出现在第一个标签中

<div class="tab-content clearfix">
 <div class="tab-pane active" id="1a">
  <form>
   <div class="g-recaptcha" id="recaptchaTab1" :data-sitekey="rcapt_sig_key"></div>
  </form>
 </div>  
</div>  
<div class="tab-content clearfix">
 <div class="tab-pane active" id="1a">
  <form>
   <div class="g-recaptcha" id="recaptchaTab2" :data-sitekey="rcapt_sig_key"></div>
  </form>
 </div>  
</div>

In javascript 在JavaScript中

data() {
 return {
  rcapt_sig_key: "site_key",
  recaptchaTab2: 0,
  recaptchaTab1: 0
  }
},
mounted() {
  if (window.grecaptcha) {
   this.rcaptIdTab2 = grecaptcha.render( 'recaptchaTab2', { sitekey : this.rcapt_sig_key });
   this.rcaptIdTab1 = grecaptcha.render( 'recaptchaTab1', { sitekey : this.rcapt_sig_key });
  }
 }

When I refresh the page,captcha is showed in the first tab. 当我刷新页面时,验证码显示在第一个选项卡中。

This is due to the way how ReCaptcha work, you cannot render multiple ReCaptcha on one page, which you are doing in your component. 这是由于ReCaptcha的工作方式所致,您无法在一个页面上呈现多个ReCaptcha,而这是您在组件中执行的。 ( https://groups.google.com/forum/#!topic/recaptcha/kOYcRJCSDXM ). https://groups.google.com/forum/#!topic/recaptcha/kOYcRJCSDXM )。

Either you let all forms share the same ReCaptcha on one page, or use popups to display the ReCaptcha or try to offload the rendering and parsing to the server and some AJAX. 您可以让所有表单在一页上共享相同的ReCaptcha,或者使用弹出窗口显示ReCaptcha,或者尝试将呈现和解析工作卸载到服务器和某些AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM