uni-app的请求

uni-app的请求

发起请求uni.request

methods:{
    
    
	get(){
    
      //绑定的方法
		uni.request({
    
    
			method:"" ,//请求方式默认是get
			url:"请求地址"success(res){
    
    
				console.log(res)
			}
		})
	}
}

数据缓存

异步

uni.setStorage 设置数据缓存
将数据存储在本地缓存中指定的key中,会覆盖掉原来改key对应的内容,这是一个异步接口

methods:{
    
    
	setStorage(){
    
    
		uni.setStorage({
    
    
			key:"id",
			data:80,
			success(){
    
    
				console.log("存储成功")
			}
		})
	}
}

uni.getStorage 获取数据缓存

methods:{
    
    
	getStorage(){
    
    
		uni.getStorage({
    
    
			key:"id",
			success(){
    
    
				console.log("获取成功")
			}
		})
	}
}

uni.removeStorage 移除数据缓存的数据 使用方法同上

同步

uni.setStorageSync 设置数据缓存
将数据存储在本地缓存中指定的key中,会覆盖掉原来改key对应的内容,这是一个同步接口

methods:{
    
    
	setStorage(){
    
    
		uni.setStorageSync('id',100)
	}
}

uni.getStorageSync 获取数据缓存

methods:{
    
    
	getStorage(){
    
    
		uni.getStorageSync('id')
	}
}

uni.removeStorageSync 移除数据缓存的数据 使用方法同上

猜你喜欢

转载自blog.csdn.net/weixin_48255917/article/details/110124878