我正在尝试加载一个一旦触发就会生成 iframe 和天气小部件的脚本。我可以正确附加脚本,但它不会被调用并且不会生成 iframe我试过直接在渲染中添加脚本,它会简单地加载 iframe 然后切换回脚本标签const City = ({ content, schema }) => { useEffect(() => { let script = document.createElement("script"); script.src = "https://darksky.net/widget/graph-bar/32.7174,-117.1628/us12/en.js?width=100%&height=400&title=Full Forecast&textColor=333333&bgColor=FFFFFF&transparency=false&skyColor=undefined&fontFamily=Default&customFont=&units=us&timeColor=333333&tempColor=ff8200¤tDetailsOption=true"; script.async = true; document.getElementById("widget").appendChild(script); }, []) return (<div id="widget"></div>);};export default City;
1 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
注意控制台中显示的警告:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
添加回答
举报
0/150
提交
取消