【问题标题】:eslint error the value of aria-current must be a single token from the following: page,step,location,date,time,true falseeslint 错误 aria-current 的值必须是来自以下的单个标记:page,step,location,date,time,true false
【发布时间】:2021-07-11 05:14:38
【问题描述】:
<div
     role="button"
     tabIndex="0"
     className="nav-link pad-0-r"
     aria-current={'${selectedTab === item ? 'page' : 'false'}'}
     onClick={()=> onClick(item)}
      onKeyDown={()=> onClick()}
     >
  {item}
</div>

** 出于安全目的,我无法分享完整的代码.... 在这个 div 中,借助地图,我正在显示导航项名称 但我收到了我提到的这个 eslint 错误。如果有人知道如何解决它,请建议我。 **

【问题讨论】:

    标签: javascript html reactjs bootstrap-4 runtime-error


    【解决方案1】:

    问题

    看起来您正在将 aria-current 设置为字符串文字的某种合并,但不确定它在 DOM 中解析为什么。

    aria-current={'${selectedTab === item ? 'page' : 'false'}'}
    

    解决方案

    正确使用字符串模板,注意反引号:

    aria-current={`${selectedTab === item ? 'page' : 'false'}`}
    

    【讨论】:

    • 反引号不会产生任何问题。感谢回复
    猜你喜欢
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    相关资源
    最近更新 更多