Vue 使用localStorage报错:_LocalStorage2.default.getItem is not a function

问题

image
在mounted中使用localStorage获取数据,没想到报错如下:
image
打断点看过localStorage中存在getItem()方法。这个问题类似之前遇到的canvas2image的那个问题(canvasToImage报错:_canvas2image2.default.convertToImage is not a function
感觉是因为目前这个项目框架太旧了,总是遇到各种奇奇怪怪的问题。

解决

发现问题原因是vscode插件自动帮我引用了项目里的工具文件,该封装不含getItem()方法:
image
把这行注释掉,就可以使用window.localStorage了。

总结:这是一个插件过于热心帮忙导致的问题。

posted @ 2023-01-17 10:52  宇宙野牛  阅读(642)  评论(0编辑  收藏  举报