小编典典

如何在ReactJs中渲染口音?

reactjs

我正在尝试使用ReactJS和JSX 渲染具有重音符号的元素,但它没有返回我想要的东西。

我的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

我该如何解决这个问题?


阅读 256

收藏
2020-07-22

共1个答案

小编典典

您所看到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çamentoOr&#231;amento

JSX陷阱中对此进行了很好的解释。

2020-07-22