在一个反应组件中,我试图合并一个纯文本唯一的contenteditable div,但是当我们使用typescript时,contenteditable属性不能是一个字符串 . 所以当我输入这个时,在我的.tsx文件中:
contentEditable={"plaintext-only"}
我收到此错误:
属性'contentEditable'的类型不兼容 . 类型'“plaintext-only”'不能赋值为'boolean |未定义” .
我怎样才能使它成为纯文本?
在一个反应组件中,我试图合并一个纯文本唯一的contenteditable div,但是当我们使用typescript时,contenteditable属性不能是一个字符串 . 所以当我输入这个时,在我的.tsx文件中:
contentEditable={"plaintext-only"}
我收到此错误:
属性'contentEditable'的类型不兼容 . 类型'“plaintext-only”'不能赋值为'boolean |未定义” .
我怎样才能使它成为纯文本?
1 回答
您需要检查属性
contentEditable
的type
,它只接受boolean
或undefined
.这就是为什么你得到错误,你试图传递
string
值 .如果将
contentEditable
的类型更新为string
而不是boolean
,则可以删除该问题