Argument of type ‘string | null‘ is not assignable to parameter of type ‘string‘. Type ‘null‘ is n

Argument of type ‘string | null‘ is not assignable to parameter of type ‘string‘. Type ‘null‘ is n_第1张图片

在在sessionStorage或本地存储进行JSON.parse转换时,可能会出现以上问题,修改方式如下:

 

原因是:

sessionStorage.getItem("detail")  方法可能返回null , 而null 不是字符串 , 则JSON.parse在执行时就会出错,所以typescript 提示了上面的错误信息,即要处理为null 的情况 

你可能感兴趣的:(前端,javascript,vue3+ts)