Skip to content

LocalStorage

LocalStorage 能够为插件提供简化的本地存储。

LocalStorage.setItem()

存储值到指定的 key。

定义

static async setItem(key: string, value: string): Promise<void>

示例

typescript
import {UI, LocalStorage} from 'sofast-extensions-test'

(async () => {
	await LocalStorage.setItem('hello', JSON.stringify({
	  'hello': 'word'
	}))
})()

LocalStorage.getItem()

获取指定 key 的值。

定义

static async getItem(key: string): Promise<string | null>

示例

typescript
import {UI, LocalStorage} from 'sofast-extensions-test'

(async () => {
	const hello = await LocalStorage.getItem('hello')
	console.log(hello) // {'hello': 'world'}
})()

LocalStorage.removeItem()

删除指定 key 的值

定义

static async removeItem(key: string): Promise<void>

示例

typescript
import {UI, LocalStorage} from 'sofast-extensions-test'

(async () => {
	await LocalStorage.removeItem('hello')
})()