我一直在尝试这一段时间,我完全停留在这个问题上,希望有人能给我一些想法,我可以如何解决这个问题。 问题在这里。requireJS和Google+ Javascript API
我想使用Google Javascript API进行我的网站登录。 我的JavaScript
define(function (require) {
init = function(){
require(['https://apis.google.com/js/platform.js?onload=renderButton'], function(gapi){
renderButton();
});
},
renderButton = function(){
console.log("renderbutton called");
gapi.signin2.render('google-signin', {
'scope': 'https://www.googleapis.com/auth/plus.login',
'width': 151,
'height': 25,
'longtitle': true,
'theme': 'dark'
});
},
});
当我做到这一点,则返回错误消息“的ReferenceError:GAPI没有定义”
所以我曾尝试如下,但没有运气。
define(function (require) {
init = function(){
require(['https://apis.google.com/js/platform.js?onload=renderButton'], function(gapi){
renderButton(gapi);
});
},
renderButton = function(gapi){
console.log("renderbutton called");
gapi.signin2.render('google-signin', {
'scope': 'https://www.googleapis.com/auth/plus.login',
'width': 151,
'height': 25,
'longtitle': true,
'theme': 'dark'
});
},
});
不能完全确定,但我认为你只需要GAPI传递到renderButton .. IE,renderButton(GAPI); 。需求似乎将您的gapi模块加载到当前作用域中,但它不能被另一个并行函数的作用域访问,而不作为参数传递 – Hypaethral
Thanks Grumble Snatch。我已经如上所述尝试过了。我不确定那是你的意思。我明白你的意思,但仍然抱怨gapi没有定义。 – redpotato