
相同点:
微信小程序 wx.setstoragesync和wx.setstorage都是能把值保存在微信小程序缓存中,类似于浏览器的localstorage概念
区别:
wx.setStorage是异步的:就是这个在执行中不会影响其他代码的执行
wx.setStorageSync是同步的:要等待这个代码执行完才会去执行其他的代码
使用范例:
setStorage:
// 设置值
wx.setStorage({
key:"key",
data:"value"
})
// 取值
wx.getStorage({
key: 'key',
success (res) {
console.log(res.data)
}
})
StorageSync:
// 设置值
wx.setStorageSync('key', 'value')
// 取值
var value = wx.getStorageSync('key')
本文详细比较了微信小程序wx.setStorageSync与wx.setStorage的区别,前者为同步操作,后者异步。通过实例演示了如何在两者间切换使用,适合开发者理解和应用。
1964

被折叠的 条评论
为什么被折叠?



