Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在运行时使用 document.createElement('script') 在我的反应代码中创建一个脚本节点并将其 src 分配给一个 url,现在我想在我的反应代码中使用包含的 JS 的变量而不声明它。
您可以简单地定义为全局like window.yourVariable = 'value',然后就可以使用了。
window.yourVariable = 'value'
window.globalVariable = { foo: 'bar', };
const Component = () => { // you can access in here. return <div></div> }