本地会话存储,关闭插件后删除。有效范围为整个插件。
存储数据
同步接口支持版本:iOS >= 6.3.0 Android >= 6.3.0
| 参数名 | 类型 | 是否可选 | 默认值 | 含义 | 
|---|---|---|---|---|
| options | Object | 选项 | ||
| options.query | Object | 需要存储的数据对象,key/value 的形式,支持多个 | ||
| options.success | Function | 可选 | 调用成功的回调函数 | |
| options.error | Function | 可选 | 调用失败的回调函数 | 
| 参数名 | 类型 | 是否一定返回 | 含义 | 
|---|---|---|---|
| result | Object | 响应对象 | |
| result.code | String | 错误码,成功为 QAP_SUCCESS;失败为其他 | |
| result.msg | String | 错误信息 | 
// 异步调用
QN.sessionstore.set({
    query: {
        name: '张三',
        age: 18,
        data: {x: 1, y: 2},
    }
}).then(result => {
    console.log(result);
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.setSync({
    query: {
        name: '张三',
        age: 18,
        data: {x: 1, y: 2},
    }
});
console.log(result); 
查询数据
同步接口支持版本:iOS >= 6.3.0 Android >= 6.3.0
| 参数名 | 类型 | 是否可选 | 默认值 | 含义 | 
|---|---|---|---|---|
| options | Object | 选项 | ||
| options.query | Object | 请求参数 | ||
| options.query.key | StringArray | 存储的 key或 以key组成的数组 | ||
| options.success | Function | 可选 | 调用成功的回调函数 | |
| options.error | Function | 可选 | 调用失败的回调函数 | 
| 参数名 | 类型 | 是否一定返回 | 含义 | 
|---|---|---|---|
| result | Object | 响应对象 | |
| result.code | String | 错误码,成功为 QAP_SUCCESS;失败为其他 | |
| result.msg | String | 错误信息 | |
| result.data | Object | 获取到的数据,格式为 key value,如果某个 key 未取到值,则 data中将不包含该 key | 
// 异步调用,获取一个 key 的数据
QN.sessionstore.get({
    query: {
        key: 'name'
    }
}).then(result => {
    console.log(result);
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.getSync({
    query: {
        key: 'name'
    }
});
console.log(result); 
// 异步调用,获取多个 key 的数据
QN.sessionstore.get({
    query: {
        key: ['name', 'age', 'data', 'job']
    }
}).then(result => {
    console.log(result);
    /**
     * // `job` 这个字段没有值,`data` 中将不包含 `job` 字段
     * {
     *   errorCode: 0,
     *   errorMsg: '',
     *   data: {
     *      name: '张三',
     *      age: '18',
     *      data: {x: 1, y: 2},
     *      job: null  // 如果存储中没有数据,则返回null
     *   }
     * }
     */
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.getSync({
    query: {
        key: ['name', 'age', 'data', 'job']
    }
});
console.log(result); 
删除数据
同步接口支持版本:iOS >= 6.3.0 Android >= 6.3.0
| 参数名 | 类型 | 是否可选 | 默认值 | 含义 | 
|---|---|---|---|---|
| options | Object | 选项 | ||
| options.query | Object | 请求参数 | ||
| options.query.key | StringArray | 存储的 key或 以key组成的数组 | ||
| options.success | Function | 可选 | 调用成功的回调函数 | |
| options.error | Function | 可选 | 调用失败的回调函数 | 
| 参数名 | 类型 | 是否一定返回 | 含义 | 
|---|---|---|---|
| result | Object | 响应对象 | |
| result.code | String | 错误码,成功为 QAP_SUCCESS;失败为其他 | |
| result.msg | String | 错误信息 | 
// 异步调用,删除一个 key 的数据
QN.sessionstore.remove({
    query: {
        key: 'name'
    }
}).then(result => {
    console.log(result);
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.removeSync({
    query: {
        key: 'name'
    }
});
console.log(result); 
// 异步调用,删除多个 key 的数据
QN.sessionstore.remove({
    query: {
        key: ['name', 'age', 'data', 'job']
    }
}).then(result => {
    console.log(result);
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.removeSync({
    query: {
        key: ['name', 'age', 'data', 'job']
    }
});
console.log(result); 
清除数据
同步接口支持版本:iOS >= 6.3.0 Android >= 6.3.0
| 参数名 | 类型 | 是否可选 | 默认值 | 含义 | 
|---|---|---|---|---|
| options | Object | 可选 | 选项 | |
| options.success | Function | 可选 | 调用成功的回调函数 | |
| options.error | Function | 可选 | 调用失败的回调函数 | 
| 参数名 | 类型 | 是否一定返回 | 含义 | 
|---|---|---|---|
| result | Object | 响应对象 | |
| result.code | String | 错误码,成功为 QAP_SUCCESS;失败为其他 | |
| result.msg | String | 错误信息 | 
// 异步调用
QN.sessionstore.clear()
.then(result => {
    console.log(result);
}, error => {
    console.log(error);
});
// 同步调用
let result = QN.sessionstore.clearSync();
console.log(result);