繁体   English   中英

如何在 React-TypeScript 的 Inline CSS 中使用“--percentage”?

[英]How can I use "--percentage" in Inline CSS in React-TypeScript?

我有一个内联样式的 div

<div className="HalfArc" style={{ "--percentage": "75%" }}>

这在我的 ReactJS 项目中运行良好。 它也适用于我的 ReactTS 项目,但我收到此 TS2322 错误:

Type '{ "--percentage": string; }' is not assignable to type 'Properties<string | number, string & {}>'.
  Object literal may only specify known properties, and '"--percentage"' does not exist in type 'Properties<string | number, string & {}>'.

我尝试在不同的 position 中设置“”,但我不知道如何消除错误。

将样式 object 转换为React.CSSProperties

const style = { "--percentage": "75%"} as React.CSSProperties;
<div className="HalfArc" style={style}>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM