Skip to content

Commit 8a9fffb

Browse files
committed
fix: #90
1 parent fa131f8 commit 8a9fffb

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

build.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42979,7 +42979,12 @@ module.exports = {
4297942979
_.runInAsync(options, res)
4298042980
},
4298142981
getStorageSync(key) {
42982-
return JSON.parse(localStorage.getItem(key))
42982+
const res = localStorage.getItem(key)
42983+
try {
42984+
return JSON.parse(res)
42985+
} catch (err) {
42986+
return res
42987+
}
4298342988
},
4298442989
getStorageInfo(options) {
4298542990
let res = {errMsg: 'getStorageInfo:ok'}

docs/update.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 更新日志
22

3+
## 1.5.6
4+
5+
* storage 系列接口支持存取字符串内容
6+
37
## 1.5.5
48

59
* 修复 global.wx 赋值会覆盖用户模拟的 wx 对象问题

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-simulate",
3-
"version": "1.5.5",
3+
"version": "1.5.6",
44
"description": "tools for miniprogram custom component unit test",
55
"main": "index.js",
66
"types": "index.d.ts",

src/api/data.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ module.exports = {
2626
_.runInAsync(options, res)
2727
},
2828
getStorageSync(key) {
29-
return JSON.parse(localStorage.getItem(key))
29+
const res = localStorage.getItem(key)
30+
try {
31+
return JSON.parse(res)
32+
} catch (err) {
33+
return res
34+
}
3035
},
3136
getStorageInfo(options) {
3237
let res = {errMsg: 'getStorageInfo:ok'}

0 commit comments

Comments
 (0)