react运行中Q&A

210 阅读1分钟

Q1:Line 11:1: Import in body of module; reorder to top import/first Search for the keywords to learn more about each error.

A1:将import引入放到 const定义之上


Q2:#185

A2:onClick没有绑定bind


Q3:Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.

A3:1)卸载已安装版本 npm uninstall node-sas.2)安装 npm install node-sass@4.14.1


Q4:./src/06_组件实例三大属性1_state/state.js Module not found: Can't resolve 'classnames'

A4:npm install classnames --save


Q5:Imported JSX component Index_05 must be in PascalCase or SCREAMING_SNAKE_CASE react/jsx-pascal-case 原因:组件命名中有下划线

A5:去掉下划线


Q5: Line 10:10: 'string' is defined but never used no-unused-vars

A5:将文件中的引用去掉即可。


Q6:All files must be modules when the '--isolatedModules' flag is provided. TS1208

A6:将没有用到的文件删掉或者使用该文件即可。


Q7:Object is possibly 'undefined'.

A7:数组需要判断是否存在;可选择值不能具体到某个数;

interface num {
    id?:number
}


// 报错,因为id为可选属性,不能大于固定值
Num?.id > 0

Q8:类型判断

id:number、undefined  -> !!id

Q9:Unexpected use of 'confirm' no-restricted-globals

A9:添加window

window.confirm('确定要删除嘛?'):boolean

......