赞
踩
在项目中用到本地缓存数据的概率非常大。例如登录信息,token,用户信息等等。
1.将数据存储到本地:
uni.setStorageSync(‘info’,this.info)
其中’info’是存到本地中的key值,this.info是存储到本地的value值。this.info是你需要存储的数据
2.获取本地中的数据
uni.getStorageSync(‘info’)
其中’info’是你存到本地中的key值。
详细代码如下:
uni.setStorageSync("userinfo", this.form)
uni.getStorageSync('userinfo')
注意:
在将数组或对象存储到本地时需要在加一个
JSON.stringify(你要存的数组)
获取本地数组时要加JSON.parse()
JSON.parse(uni.getStorageSync(你要获取的数组))
详细代码如下:
uni.setStorageSync("serviceList", JSON.stringify(this.serviceList))
JSON.parse(uni.getStorageSync('serviceList'))
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。