Home  >  Article  >  Web Front-end  >  What to do if uniapp sync cache fails

What to do if uniapp sync cache fails

coldplay.xixi
coldplay.xixiOriginal
2020-12-08 15:41:506613browse

Solution to uniapp synchronization cache failure: 1. Set the storage, the code is [uni.setStorageSync('storage_key', 'hello')]; 2. Get the relevant information of the current storage, the code is [console. log(res.keys)].

What to do if uniapp sync cache fails

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer. This method is suitable for all brands of computers.

Recommended (free): uni-app development tutorial

Solution to uniapp synchronization cache failure :

Save

try {
    uni.setStorageSync('storage_key', 'hello');
} catch (e) {
    // error
};

Get

try {
    const value = uni.getStorageSync('storage_key');
    if (value) {
        console.log(value);
    }
} catch (e) {
    // error
};

Get the relevant information of the current storage

try {
    const res = uni.getStorageInfoSync();
    console.log(res.keys);
    console.log(res.currentSize);
    console.log(res.limitSize);
} catch (e) {
    // error
};

Remove the specified key

try {
    uni.removeStorageSync('storage_key');
} catch (e) {
    // error
};

Clear local data cache

try {
    uni.clearStorageSync();
} catch (e) {
    // error
};

Related free learning recommendations: Programming video

The above is the detailed content of What to do if uniapp sync cache fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn