Skip to Content
React快速上手开发
book

React快速上手开发

by Stoyan Stefanov
March 2017
Intermediate to advanced
210 pages
5h 1m
Chinese
Posts & Telecom Press
Content preview from React快速上手开发
144
7
href: ?string,
className: ?string,
};
7.3.5
 
app.js
对主文件
app.js
运行检查,会得到如下错误:
$ flow js/source/app.js
js/source/app.js:11
11: let data = JSON.parse(localStorage.getItem('data'));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of method `getItem`
11: let data = JSON.parse(localStorage.getItem('data'));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null. This type is
incompatible with
383: static parse(text: string, reviver?: (key: any, value: any) => any):
any;
^^^^^^ string. See lib: /private/tmp/flow/flow
lib_28f8ac7e/core.js:383
Flow
要求你只能传递字符串到
JSON.parse()
函数中,并且帮你指出了
parse()
函数所在的
位置。由于
localStorage.getItem
可能会返回
null
,这是不可接受的。一种简单的解决方
案是添加默认值:
let data = JSON.parse(localStorage.getItem('data') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JSON實務手冊

JSON實務手冊

Tom Marrs
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
React学习手册

React学习手册

Alex Banks, Eve Porcello
数据压缩入门

数据压缩入门

Colt McAnlis, Aleks Haecky

Publisher Resources

ISBN: 9787115447739