学无先后,达者为师

网站首页 编程语言 正文

uniapp封装本地存储处理数据的方法和具体使用

作者:Wxinin 更新时间: 2022-04-23 编程语言

js文件

//存储数据
function setStoraged(data1, data2) {
    uni.setStorage({
        key: data1,
        data: JSON.stringify(data2),
    })
}
//获取数据
function getStoraged(data1) {
    const data = uni.getStorageSync(data1);
    if (data) {
        return data;
    } else {
        return [];
    }

}
//删除数据
function removeStoraged(data1) {
    uni.removeStorageSync(data1);
}
export {
    setStoraged,
    getStoraged,
    removeStoraged
}

页面应用

导入

import {
        setStoraged,
        getStoraged,
        removeStoraged
    } from '../../unils/storageData.js'

使用

 setStoraged('value', '123');
  let datas = getStoraged('colData');
  if (datas[0]) {
     datasArr = JSON.parse(getStoraged('colData'));
   }
   removeStoraged('value');         

原文链接:https://blog.csdn.net/weixin_44283589/article/details/121771796

栏目分类
最近更新