美文网首页
: Unexpected token u in JSON at

: Unexpected token u in JSON at

作者: 黑白说程序 | 来源:发表于2020-11-16 22:28 被阅读0次

: Unexpected token u in JSON at position错误
这是因为localStorage.getItem("cart")获取的值是undefined
解决方法
var cart= localStorage.getItem("cart");
if(Object.keys(cart)){
var cartlist = JSON.parse(localStorage.getItem("cart")) || [];
}else{
var cartlist=[]
}

相关文章

网友评论

      本文标题:: Unexpected token u in JSON at

      本文链接:https://www.haomeiwen.com/subject/hihtiktx.html