https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
"use client"
import React, {useEffect} from 'react';
export const ExternalScriptLoader = () => {
useEffect(() => {
// 创建script标签
const script = document.createElement("script");
script.src = "http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js";
script.async = true;
document.body.appendChild(script);
// 添加加载完成的监听器
script.onload = () => {
// 执行加载完成后的额外代码
const obj = window.WxLogin({
id: "login_container",
appid: "wx38f314ab95e7339b",
scope: "snsapi_login",
redirect_uri: "http://mklxai.com.cn/api/openapi/wx/callback/login",
state: "213S213TATE",
style: "",
href: ""
})
// 在这里执行额外的操作,例如初始化微信登录
// initWeChatLogin();
};
// 添加加载失败的监听器(可选)
script.onerror = () => {
console.error("Failed to load external script.");
// 可以在加载失败时执行相应的操作
};
// 将脚本添加到 body 中
}, []);
return (
<div id="login_container" className={"flex justify-center "}/>
);
};
export default ExternalScriptLoader;