Object is possibly null || Object is possibly null: 对象可能是null【解决办法】

今天爱分享给大家带来vue:typescript 提示Object is possibly null || Object is possibly null: 对象可能是null【解决办法】,希望能够帮助到大家。

Object is possibly null: 对象可能是null

分析:localStorage.getItem(“SET_HISTORY_KEY”) 这个值有可能为空,所以再执行getItem就会报错此刻对象可能为空。

解决:

1.联合类型 把null的情况写入

2.类型断言成any类型,any类型上访问任何属性和方法都是被允许的。

人已赞赏
前端

(in promise) MiniProgramError {“errMsg“:“navigateTo:fail can not navigateTo a tabbar page“}【解决办法】

2020-11-11 9:48:16

前端

Props with type Object/Array must use a factory function to return the default value【解决办法】

2020-11-11 9:53:04

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
'); })();