如何在react render函数中使用ejs变量? [英] How to use an ejs variable inside a react render function?
本文介绍了如何在react render函数中使用ejs变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将变量 abcd
传递给我的index.ejs,该变量反过来调用react js文件来呈现index.ejs页面。我已经可以在index.ejs内访问<%= abcd%>
,但不能在react的渲染功能内访问。您能帮帮我吗?
I'm passing a variable abcd
to my index.ejs which in turn calls a react js file to render the index.ejs page. I've been able to access <%= abcd %>
inside index.ejs but not inside the render function of react. Can you help me out?
谢谢
推荐答案
我遇到了相同的问题,但是有一个由React组件填充的index.html文件,并像这样解决了它:
I faced the same problem but with a index.html file, filled by a React component, and resolved it like this:
在index.html
<script>
window.abcd = '<%- abcd %>';
</script>
在您的反应组件中
render: function(){
return(
<div>
<p> {window.abcd} </p>
</div>
);
}
这对我来说非常有效,如果有人提出更明确的主张,我就是在!
This worked perfectly for me, if someone has a cleaner proposition, i'm in!
这篇关于如何在react render函数中使用ejs变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文