Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro转百度小程序,getStorageSync获取本地数据与百度小程序格式不同 #3556

Closed
vfiee opened this issue Jun 26, 2019 · 6 comments
Labels
question Further information is requested

Comments

@vfiee
Copy link

vfiee commented Jun 26, 2019

问题描述
Taro转百度小程序使用Taro.getStorageSync(key)应该直接返回缓存数据,但是缓存数据格式与百度小程序getStorage格式相同

复现步骤

  1. 项目编译成百度小程序
  2. 使用Taro.getStorageSync()
  3. 控制台打印数据格式为{data:本地缓存}
  4. 参考https://smartprogram.baidu.com/docs/develop/api/storage_save/#swan-getStorage/
 let sto = Taro.getStorageSync('key');
 console.log(sto);
控制台打印数据:{data: false}

期望行为
期望直接返回false
特别说明:在开发工具中多次尝试,刚开始几次是直接返回false,但是多编译和刷新几次之后,就会返回对象模式的数据

报错信息
Taro.getStorageSync()返回数据格式不正确

系统信息
Taro CLI 1.3.4 environment info:
System:
OS: macOS 10.14.5
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.5.0 - /usr/local/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.5.0 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: 1.3.4 => 1.3.4
@tarojs/components: 1.3.4 => 1.3.4
@tarojs/plugin-babel: 1.3.4 => 1.3.4
@tarojs/plugin-csso: 1.3.4 => 1.3.4
@tarojs/plugin-less: 1.3.4 => 1.3.4
@tarojs/plugin-uglifyjs: 1.3.4 => 1.3.4
@tarojs/redux: 1.3.4 => 1.3.4
@tarojs/router: 1.3.4 => 1.3.4
@tarojs/taro: 1.3.4 => 1.3.4
@tarojs/taro-alipay: 1.3.4 => 1.3.4
@tarojs/taro-h5: 1.3.4 => 1.3.4
@tarojs/taro-swan: 1.3.4 => 1.3.4
@tarojs/taro-tt: 1.3.4 => 1.3.4
@tarojs/taro-weapp: 1.3.4 => 1.3.4
@tarojs/webpack-runner: 1.3.4 => 1.3.4
eslint-config-taro: 1.3.4 => 1.3.4
eslint-plugin-taro: 1.3.4 => 1.3.4
nerv-devtools: ^1.4.3 => 1.4.3
nervjs: ^1.4.3 => 1.4.3

@taro-bot
Copy link

taro-bot bot commented Jun 26, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 27, 2019

@vfiee
Copy link
Author

vfiee commented Jun 28, 2019

@vfiee https://nervjs.github.io/taro/docs/debug.html#api-%E9%97%AE%E9%A2%98

我在百度小程序文档中(https://smartprogram.baidu.com/docs/develop/api/storage_save/#swan-setStorageSync/)开发者预览是没有问题的。
查看native-apis.js中只有
setStorage: true,
getStorage: true,
getStorageInfo: true,
removeStorage: true,
clearStorage: true,
没有
setStorageSync: true,
getStorageSync: true

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 28, 2019

特别说明:在开发工具中多次尝试,刚开始几次是直接返回false,但是多编译和刷新几次之后,就会返回对象模式的数据

@vfiee 没有复现,都是直接返回值。而且你在 Taro.getStorageSync 打个断点看看,就知道相当于直接调用 swan.getStorageSync。如果真的有你说的情况,也是百度的问题。

@Chen-jj Chen-jj added answered question Further information is requested labels Jun 28, 2019
@vfiee
Copy link
Author

vfiee commented Jun 28, 2019

特别说明:在开发工具中多次尝试,刚开始几次是直接返回false,但是多编译和刷新几次之后,就会返回对象模式的数据

@vfiee 没有复现,都是直接返回值。而且你在 Taro.getStorageSync 打个断点看看,就知道相当于直接调用 swan.getStorageSync。如果真的有你说的情况,也是百度的问题。

我先把这个问题关闭了,因为之前确实有这样的问题,但是今天我升级项目Cli版本之后没有这个问题了

@polichan
Copy link

polichan commented Jun 9, 2020

我现在也出现这个问题了,假设我传的是

Taro.setStorageSync("test", {test: "2222"})

localStorage 里显示的是 {data: {test: "2222"}}
CLI是 Taro v2.2.7是在 H5 版本下会出现这个问题。不知道如何解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants