在从localstrage取变量的时候赋值提示此报错 为什么?
TS2322: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
在从localstrage取变量的时候赋值提示此报错 为什么?
TS2322: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
localStorage中的authorName键不存在,返回null了,错误提示null无法赋值给string类型变量,做个兼容
this.authorName=localStorage.getItem('authorName')||'';//为null则默认为空字符串