Skip to content

本地存储模块

数据结构

接口

getBoolean

该方法获取Boolean类型的值。

完整方法声明:function getBoolean(key: string, defValue: boolean): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
defValue默认值boolean
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

putBoolean

该方法存储Boolean类型的值。

完整方法声明:function putBoolean(key: string, value: boolean): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
valuevalueboolean
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

getInt

该方法获取Int类型的值。

完整方法声明:function getInt(key: string, defValue: number): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
defValue默认值number
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

putInt

该方法存储Int类型的值。

完整方法声明:function putInt(key: string, value: number): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
valuevaluenumber
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

getLong

该方法获取Long类型的值。

完整方法声明:function getLong(key: string, defValue: number): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
defValue默认值number
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

putLong

该方法存储Long类型的值。

完整方法声明:function putLong(key: string, value: number): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
valuevaluenumber
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

getString

该方法获取String类型的值。

完整方法声明:function getString(key: string, defValue: string): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
defValue默认值string
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

putString

该方法存储String类型的值。

完整方法声明:function putString(key: string, value: string): Promise<boolean>

  • 参数:
参数描述类型非空
keykeystring
valuevaluestring
  • 返回值:
属性描述类型默认值
是否成功Promise<boolean>

基础用法

  • 代码示例:
    点击查看源码
    vue
    <template>
    	<div class='es-sdk-root-css'>
    		<s-title-view class='es-sdk-content-title-css' :text='this.$options.name' />
    		<div class='es-sdk-content-divider-css' />
    		<div class='es-sdk-content-row-css'>
    			<div class='es-sdk-content-row-css'>
    				<s-text-button text='getBoolean' @onButtonClicked='getBoolean' />
    				<s-text-button text='putBoolean' @onButtonClicked='putBoolean' />
    				<s-text-button text='getInt' @onButtonClicked='getInt' />
    				<s-text-button text='putInt' @onButtonClicked='putInt' />
    				<s-text-button text='getLong' @onButtonClicked='getLong' />
    				<s-text-button text='putLong' @onButtonClicked='putLong' />
    				<s-text-button text='getString' @onButtonClicked='getString' />
    				<s-text-button text='putString' @onButtonClicked='putString' />
    			</div>
    		</div>
    	</div>
    </template>
    
    <script lang='ts'>
    
    import {defineComponent} from '@vue/runtime-core';
    import {useESLocalStorage, useESToast} from '@extscreen/es3-core';
    
    export default defineComponent({
    	name: '本地存储',
    	setup() {
    
    		const localStorage = useESLocalStorage();
    		const toast = useESToast();
    
    		function getBoolean() {
    			localStorage.getBoolean('boolean_key', false)
    				.then(
    					(value) => {
    						toast.showToast('getBoolean:' + value);
    					},
    					error => {
    					},
    				);
    		}
    
    		function putBoolean() {
    			localStorage.putBoolean('boolean_key', true)
    				.then(
    					() => {
    					},
    					error => {
    					},
    				);
    		}
    
    		function getInt() {
    			localStorage.getInt('int_key', -1)
    				.then(
    					(value) => {
    						toast.showToast('getInt:' + value);
    					},
    					error => {
    					},
    				);
    		}
    
    		function putInt() {
    			localStorage.putInt('int_key', 20000)
    				.then(
    					() => {
    					},
    					error => {
    					},
    				);
    		}
    
    		function getLong() {
    			localStorage.getLong('long_key', 0)
    				.then(
    					(value) => {
    						toast.showToast('getLong:' + value);
    					},
    					error => {
    					},
    				);
    		}
    
    		function putLong() {
    			localStorage.putLong('long_key', 20000000)
    				.then(
    					() => {
    					},
    					error => {
    					},
    				);
    		}
    
    		function getString() {
    			localStorage.getString('string_key', 'default string !')
    				.then(
    					(value) => {
    						toast.showToast('getString:' + value);
    					},
    					error => {
    					},
    				);
    		}
    
    		function putString() {
    			localStorage.putString('string_key', 'hello local storage ~~~')
    				.then(
    					() => {
    					},
    					error => {
    					},
    				);
    		}
    
    		return {
    			getBoolean,
    			putBoolean,
    			getInt,
    			putInt,
    			getLong,
    			putLong,
    			getString,
    			putString,
    		};
    	},
    });
    
    </script>
    <style>
    </style>