uniapp 数据缓存的一些坑
在uniapp 开发中 当需要在获取缓存中的值时使用uni.getStorage()代码如下:uni.getStorage({key:keyword,success:function(res){this.searchData = res.data}})console.log(this.searchData)但是 你会发现 输出的结果是空的...
·
在uniapp 开发中 当需要在获取缓存中的值时使用uni.getStorage()
代码如下:
uni.getStorage({
key:keyword,
success:function(res){
this.searchData = res.data
}
})
console.log(this.searchData)
但是 你会发现 输出的结果是空的
正确的代码如下:
var self = this
uni.getStorage({
key:keyword,
success:function(res){
self.searchData = res.data
console.log(self.searchData,self)
console.log(this)
}
})
因为在这个api中 this的作用域发生了改变
更多推荐
已为社区贡献1条内容
所有评论(0)