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

onPreload 在什么情况会使用 #8

Closed
Anan2014 opened this issue Dec 4, 2017 · 9 comments
Closed

onPreload 在什么情况会使用 #8

Anan2014 opened this issue Dec 4, 2017 · 9 comments

Comments

@Anan2014
Copy link

Anan2014 commented Dec 4, 2017

No description provided.

@switer
Copy link
Member

switer commented Dec 5, 2017

假设场景:有 A、B两个页面,其中 A 页面为入口打开页面,在A页面ready后调用 .$preload("B") 会触发B页面类级别(还取不到页面实例)的 onPreload 调用,在 onPreload 里发起请求获取数据,就实现了数据的预加载。

@Anan2014
Copy link
Author

请问,在B页面获取数据后,如何进行保存呢,this.$setData() 方法不可用,有没有好的方法

@switer
Copy link
Member

switer commented Dec 26, 2017

你可以从文档里了解下 $put 与 $take 方法:

qq20171226-172639 2x

@Anan2014
Copy link
Author

Anan2014 commented Dec 26, 2017

请问这个 $put $cookie $session 这3者的区别有哪些,或者这样说,在哪些场景下使用比较合适

@switer
Copy link
Member

switer commented Dec 26, 2017

没有操作cookie,只有$cache
三者的区别在于:

  • $put 是内存级别的缓存,可以存放任何的对象实例、包括引用值或者是函数
  • $session 是基于本地缓存实现的临时缓存,小程序关闭后(一般是微信进程重启)会清空
  • $cache 是永久缓存,微信卸载了会清空(或者程序的清空缓存)

@Anan2014
Copy link
Author

请问小程序只能通过 setDate的方式修改页面上的值吗

@switer
Copy link
Member

switer commented Dec 28, 2017

小程序的 setData 应该算是唯一的更新接口..

@Anan2014
Copy link
Author

该框架 $cache 有删除的方法吗

@switer
Copy link
Member

switer commented Dec 29, 2017

目前没有删除的方法,$cahce.set(key, null | '') 效果也是一样的

@switer switer closed this as completed Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants