繁体   English   中英

WebStorm未解决的变量警告

[英]WebStorm unresolved variable warning

我将WebStorm用于React JS,并且所有道具都收到此“未解决的变量警告”。

在此处输入图片说明

但是一切工作都没有问题,语言已经定义,它存在。 代码有效,我的应用程序没有任何问题。

这是我在“ Languages & Frameworks > JavaScript > Libraries

在此处输入图片说明

知道如何避免这些警告吗?

更新

发生这种情况的代码示例。 第一父组件:

import ExpirationTimer from '../../common/expirationTimer';

export default class ListView extends React.Component {
    render (){
        const language = this.props.language;
        let expirationDate = "Wed May 10 2017 15:58:59 GMT+0200";

        return (
            <div>
                <ExpirationTimer expirationDate={expirationDate} language={language}/>
            </div>
        )
    }
}

语言是对象的地方{lowestPrice: "Lowest price", mileage: "Mileage", ....}

然后我尝试获取这些道具的组件起作用了,但是我得到警告,提示它们未解决:

 export default class ExpirationTimer extends React.Component {
    constructor(props){
        super(props);

        this.state = {                
            expirationDate: this.props.expirationDate // Here I get the warning
        };
    }

    render(){
        let language = this.props.language; // Here I get the warning


        return (
            <div>
                .....
            </div>
        );
    }
}

使用解构赋值: let {language} = this.props代替let language = this.props.language;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM