【问题标题】:Property 'title' does not exist on type 'IntrinsicAttributes & IProps'类型“IntrinsicAttributes & IProps”上不存在属性“标题”
【发布时间】:2019-12-23 03:06:11
【问题描述】:

那里。我试图让一个项目在另一个视图中不可见,我正在使用接口解决这个问题。

问题是我收到了这个问题标题中的错误。

这是部分代码,以便您了解发生了什么:

interface IProps {
  isDisplayedLoadingTitle: boolean;
}

export default (props: IProps) => (
  <Fragment>
    {isDisplayedLoadingTitle && (
    <ChartLoaderUI.ChartTitleContainer>
      <ChartLoaderUI.ChartTitle>
        <ChartLoaderUI.Title>{`Loading...`}</ChartLoaderUI.Title>
      </ChartLoaderUI.ChartTitle>
    </ChartLoaderUI.ChartTitleContainer>
    )}

我在其他文件中添加标签&lt;ChartLoader isDisplayedLoadingTitle={true}/&gt; 以在视图中呈现它。

我该如何解决这个问题,另一个问题:我可以选择它是真还是假这一事实实际上会隐藏标志内的内容 ({isDisplayedLoadingTitle &amp;&amp; ()?

提前感谢您的帮助。

【问题讨论】:

    标签: reactjs typescript


    【解决方案1】:

    您没有访问实际 props 对象上的 prop。你会想使用props.isDisplayedLoadingTitle &amp;&amp;。或者,您可以通过将 (props: IProps) 替换为 ({ isDisplayedLoadingTitle}: IProps) 来从 props 对象中解构它,然后保留现有代码。

    至于标题的问题,我什至看不到该道具的访问位置,因此这可能是 ChartLoaderUI 组件的问题。您必须在尝试访问 title 属性的位置发布代码,或者如果这是您构建的组件,则发布 ChartLoaderUI 的代码。

    【讨论】:

    • 很好,现在可以编译了。现在问题来了:当我这样做时&lt;ChartLoader isDisplayedLoadingTitle={false}/&gt;它不会隐藏元素。
    猜你喜欢
    • 2019-07-31
    • 2021-05-07
    • 2021-08-23
    • 2022-12-11
    • 2022-12-30
    • 2020-09-03
    • 2021-04-10
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多