未处理的运行时错误类型错误:无法读取未定义的属性(读取"包含")


const toggleCart = ()=> {
> 14 |     if (ref.current.clasList.contains('translate-x-full')){
|                             ^
15 |       ref.current.clasList.remove('translate-x-full')
16 |       ref.current.clasList.add('translate-x-0')
17 |     }

面临问题所有导入都正确但不工作

您应该像Jakub提到的那样修复错别字。

为了安全起见,最好在Typescript中使用可选通道——详见:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html

最新更新