我正在关注https://developers.google.com/identity/gsi/web/guides/display-button#javascript将 Google 登录添加到我的 ReactJS 应用程序中。
我添加了
<script>
function handleCredentialResponse(response) {
console.log("Encoded JWT ID token: " + response.credential);
}
window.onload = function () {
google.accounts.id.initialize({
client_id: "YOUR_GOOGLE_CLIENT_ID",
callback: handleCredentialResponse,
});
google.accounts.id.renderButton(
document.getElementById("buttonDiv"),
{ theme: "filled_blue", size: "large", shape: "pill" } // customization attributes
);
google.accounts.id.prompt(); // also display the One Tap dialog
};
</script>
Run Code Online (Sandbox Code Playgroud)
在 中index.html,在我的组件中,我有一个<div id="buttonDiv"></div>.
但是,当我重新加载页面时会发生以下情况:
加载的初始按钮是正确的,但不知何故调整了大小。我在调试器中暂停了JS执行,发现最初的按钮纯粹是divs,但是调整大小后,它用了aniframe代替。