所以我的问题是为什么这有效并显示点:
<Field label="Password" value="•••••" type="password" />
上面只显示了普通的六进制代码!
<Field label="Password" value={`${'•'.repeat(10)}`} type="password" />
我的字段组件:
function renderValueByType(value: string, type: string) {
switch (type) {
case 'phone':
return phoneFormatter(value);
default:
return value;
}
}
/**
*
* @param {*} param0
*/
const Field = ({ label, value, type, className }: PropTypes) => (
<div className={className}>
<span className="Field__label">{label}</span>
<span className="Field__content">{renderValueByType(value, type)}</span>
</div>
);
最佳答案
如果您将静态字符串设置为 prop,它将按原样呈现。
如果您将变量设置为 prop,它将被清除。
最好的办法是在将十六进制字符代码传递给组件之前将其转换为字符串(使用 String.fromCharCode()
):
<Field
label="Password"
value={String.fromCharCode("0x2022").repeat(10)}
type="password"
/>
关于javascript - 无法在 react jsx 值 Prop 中重复十六进制 html 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46727543/