• uniapp 缓存多个数据


    获取

                uni.getStorage({
                    key:'username',
                }).then(res => {
                    // 如果返回数组为两位就是正确
                    if(res.length==2){
                        this.username = res[1].data;
                    }
                    return uni.getStorage({
                        key:'password',
                    })
                }).then(res => {
                    if(res.length==2){
                        this.password = res[1].data;
                    }
                    return uni.getStorage({
                        key:'ipAddress',
                    })
                }).then(res => {
                    if(res.length==2){
                        this.ipAddress = res[1].data;
                    }
                })
                uni.getStorage({
                    key:'username',
                }).then(res => {
                    // 如果返回数组为两位就是正确
                    if(res.length==2){
                        this.username = res[1].data;
                    }
                    return uni.getStorage({
                        key:'password',
                    })
                }).then(res => {
                    if(res.length==2){
                        this.password = res[1].data;
                    }
                    return uni.getStorage({
                        key:'ipAddress',
                    })
                }).then(res => {
                    if(res.length==2){
                        this.ipAddress = res[1].data;
                    }
                })

      添加

    uni.setStorage({
                                    key:'token',
                                    data: res.access_token,
                                }).then(res => {
                                    // console.log("保存token");
                                    return uni.setStorage({
                                        key:'username',
                                        data: this.username,
                                    })
                                }).then(res => {
                                    // console.log("保存name");
                                    return uni.setStorage({
                                        key:'password',
                                        data: this.password,
                                    })
                                }).then(res => {
                                    // console.log("保存password");
                                    return uni.setStorage({
                                        key:'ipAddress',
                                        data: this.ipAddress,
                                    })
                                }).then(res => {
                                    // console.log("保存ipAddress");
                                    uni.switchTab({
                                        url: './home'
                                    })
                                })					

      

  • 相关阅读:
    修改浏览器滚动条样式
    js实现无缝轮播
    JS (canvas) 两个小球碰撞
    js里div随着鼠标一起移动
    js的动态加载、缓存、更新以及复用
    js阻止事件冒泡的两种方法
    核心DOM和html DOM的区别
    JavaScript 事件流、事件处理程序及事件对象总结
    css3 实现飞入由小变大
    简单手写js轮播
  • 原文地址:https://www.cnblogs.com/fhysy/p/15662633.html
Copyright © 2020-2023  润新知