Javascript 使用谷歌&x27;在Aurelia应用程序中使用s reCAPTCHA
我一直在谷歌上搜索,但似乎找不到在Aurelia应用程序中使用的方法 如果可能的话,我想将其用作自定义元素Javascript 使用谷歌&x27;在Aurelia应用程序中使用s reCAPTCHA,javascript,recaptcha,aurelia,Javascript,Recaptcha,Aurelia,我一直在谷歌上搜索,但似乎找不到在Aurelia应用程序中使用的方法 如果可能的话,我想将其用作自定义元素 从'aurelia framework'导入{inject,customElement}; //可能来自url,比如https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit 从“google recaptcha”导入recaptcha; @customElement(‘验证码’) @注射(再注
从'aurelia framework'导入{inject,customElement};
//可能来自url,比如https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit
从“google recaptcha”导入recaptcha;
@customElement(‘验证码’)
@注射(再注射)
导出类验证码{
构造器(recaptcha){
this.recaptcha=recaptcha;
}
//添加代码以初始化验证码并处理回调
}
以下是如何创建显示reCAPTCHA的自定义元素:
recaptcha.js
import{inject,noView,bindable}来自“aurelia框架”;
const recaptchaCallbackName='setRecaptchaReady';
const ready=new Promise(resolve=>window[recaptchaCallbackName]=resolve);
// https://developers.google.com/recaptcha/docs/display#explicit_render
让script=document.createElement('script');
script.src=`https://www.google.com/recaptcha/api.js?onload=${recaptchaCallbackName}&render=explicit`;
script.async=true;
script.defer=true;
document.head.appendChild(脚本);
const sitekey='6LcddxgTAAAAAMmkEMa1Vrp6TNcZG8kMMkcn VCK';
@noView()
@注入(元素)
出口类Recaptcha{
@可绑定验证;
@可绑定主题='light';
构造函数(元素){
this.element=元素;
}
附({
ready.then(()=>grecaptcha.render(this.element,{
sitekey:sitekey,
主题:这个主题,
回调:这是已验证的
}));
}
}
用法:
以下是如何创建显示reCAPTCHA的自定义元素:
recaptcha.js
import{inject,noView,bindable}来自“aurelia框架”;
const recaptchaCallbackName='setRecaptchaReady';
const ready=new Promise(resolve=>window[recaptchaCallbackName]=resolve);
// https://developers.google.com/recaptcha/docs/display#explicit_render
让script=document.createElement('script');
script.src=`https://www.google.com/recaptcha/api.js?onload=${recaptchaCallbackName}&render=explicit`;
script.async=true;
script.defer=true;
document.head.appendChild(脚本);
const sitekey='6LcddxgTAAAAAMmkEMa1Vrp6TNcZG8kMMkcn VCK';
@noView()
@注入(元素)
出口类Recaptcha{
@可绑定验证;
@可绑定主题='light';
构造函数(元素){
this.element=元素;
}
附({
ready.then(()=>grecaptcha.render(this.element,{
sitekey:sitekey,
主题:这个主题,
回调:这是已验证的
}));
}
}
用法: