首页 文章

contentEditable = {“plaintext-only”}在一个带有typescript的react组件中

提问于
浏览
0

在一个反应组件中,我试图合并一个纯文本唯一的contenteditable div,但是当我们使用typescript时,contenteditable属性不能是一个字符串 . 所以当我输入这个时,在我的.tsx文件中:

contentEditable={"plaintext-only"}

我收到此错误:

属性'contentEditable'的类型不兼容 . 类型'“plaintext-only”'不能赋值为'boolean |未定义” .

我怎样才能使它成为纯文本?

1 回答

  • 4

    您需要检查属性 contentEditabletype ,它只接受 booleanundefined .

    这就是为什么你得到错误,你试图传递 string 值 .

    如果将 contentEditable 的类型更新为 string 而不是 boolean ,则可以删除该问题

相关问题