Skip to content

Commit 22bb456

Browse files
songkeyscncolder
authored andcommitted
fix: JSON.stringify to set value in storage
1 parent ee16a58 commit 22bb456

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bom/storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class TaroStorage implements Storage {
5151
*/
5252
setItem(keyName: string, keyValue: string): void {
5353
try {
54-
const value = String(keyValue)
54+
const value = keyValue === 'string' ? keyValue : JSON.stringify(keyValue)
5555
Taro.setStorageSync(keyName, value)
5656
} catch (e) {
5757
// should throw a "QuotaExceededError" DOMException
@@ -114,7 +114,7 @@ class SessionStorage implements Storage {
114114
* Throws a "QuotaExceededError" DOMException exception if the new value couldn't be set. (Setting could fail if, e.g., the user has disabled storage for the site, or if the quota has been exceeded.)
115115
*/
116116
setItem(keyName: string, keyValue: string): void {
117-
const value = String(keyValue)
117+
const value = keyValue === 'string' ? keyValue : JSON.stringify(keyValue)
118118
this.storage.set(keyName, value)
119119
}
120120
}

0 commit comments

Comments
 (0)