我正在尝试使用ReactJS和JSX 渲染具有重音符号的元素,但它没有返回我想要的东西。
ReactJS
我的JSX:
var Orcamento = React.createClass({ render: function() { return ( <div> <h1>Orçamento</h1> </div> ); } }); React.render( <Orcamento/>, document.getElementById("orcamento") );
我呈现的JavaScript:
var Orcamento = React.createClass({displayName: "Orcamento", render: function() { return ( React.createElement("div", null, React.createElement("h1", null, "Orçamento") ) ); } }); React.render( React.createElement(Orcamento, null), document.getElementById("orcamento") );
我在浏览器中的结果:
Orçamento
我已经<meta charset="UTF-8">在head标签内的索引文件中进行了设置,如果直接在页面内容中键入该单词,则重音字符将在页面标题和正文中起作用,但是在由ReactJs
<meta charset="UTF-8">
head
ReactJs
我该如何解决这个问题?
您所看到Orçamento的是由于UTF-8字节数组以ASCII呈现的结果,可能是代码页ISO 8859-1。
ReactJS在HTML中不支持非ASCII字符。
试试这个:
var Orcamento = React.createClass({ render: function() { return ( <div> <h1> { 'Orçamento' } </h1> </div>; ); } });
或直接替换orçamento为Orçamento。
orçamento
Orçamento
JSX陷阱中对此进行了很好的解释。