我有加载外部脚本的问题中反应JSX异步加载脚本中的反应成分
<script>
(function(d) {
var config = {
kitId: 1234567,
scriptTimeout: 3000,
async: true
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
</script>
,这里是我的渲染功能,在这里我想有javascipt的负载ASYN,它在一个HTML文件超级简单,但是我如何做到这一点在一个反应组件中惊呆了。 (如果我可以避免安装另一个外部模块将是最好的)。非常感谢
render() {
return (
<head>
//Script to load asyn
</head>
)
}
你正在试图做将不起作用怎么办。相反,请尝试'componentDidMount()'内的以下策略之一:http://stackoverflow.com/questions/13121948/dynamically-add-script-tag-with-src-that-may-include-document-write – azium
反应组件正在注入您的HTML? – hazardous
是的,我不清楚你想要做什么。你可以提供一个不起作用的小提琴吗? –