错误:字符串-错误字符串:类型‘src/app/MyComponents/todos/todos.component.ts:13:5 |TS2322’不可分配给类型'string‘。不能赋值给'string‘类型。类型'null‘不可赋值给类型'string’。
13 this.localItem =localStorage.getItem(“待办事项”);
发布于 2021-12-02 09:42:49
localStorage.getItem可以返回null。您需要添加null检查。
const todos = localStorage.getItem("todos");
if (todos) {
this.localItem = todos;
}发布于 2021-12-03 10:45:49
确保在设置本地存储项时,我们应该在响应中调用令牌,例如,
localStorage.setItem("jwt",response.token);
您已将令牌作为第二个参数传递。
转到Google chrom中的开发人员工具,检查本地存储中的名称是否与您在此处传递的名称相同。
https://stackoverflow.com/questions/70197106
复制相似问题