Function getLocalStorage

  • EN: Handle Storage (Keep fit for JSON, it can transfer format automatically).

    ZH: 存储/获取数据到 sessionStorage/localStorage。

    Usage:

    setSessionStorage('test', '123');
    const ret1 = getSessionStorage('test');
    setLocalStorage('test', '123');
    const ret2 = getLocalStorage('test');
    console.log(ret1, ret2);

    // or package in usage
    const projectName = 'mazey';
    function mSetLocalStorage (key, value) {
    return setLocalStorage(`${projectName}_${key}`, value);
    }

    function mGetLocalStorage (key) {
    return getLocalStorage(`${projectName}_${key}`);
    }

    Output:

    123 123
    

    Type Parameters

    • T

    Parameters

    • key: string

    Returns T | null

    返回值