close
The Wayback Machine - https://web.archive.org/web/20200704201643/https://github.com/NervJS/taro/issues/6755
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 Next] 如何获取 index.config.ts 中的页面配置数据 #6755

Open
Songkeys opened this issue Jun 21, 2020 · 2 comments
Open

[Taro Next] 如何获取 index.config.ts 中的页面配置数据 #6755

Songkeys opened this issue Jun 21, 2020 · 2 comments
Assignees
Milestone

Comments

@Songkeys
Copy link
Contributor

@Songkeys Songkeys commented Jun 21, 2020

请教一下,3.0 里有获取当前页面配置文件的 API 吗?

想写一个 hooks 获取 config 文件中的导航标题,然后放在自己写的导航组件中。

目前我只找到 getApp() 可以获取 app 的全局配置,请问页面的有吗?

理想使用方式:

const { navigationBarTitleText } = Taro.usePageConfig()

如果实现,需要注意的地方:使用 setNavigationBarTitle() 之后,这个配置是否应该发生改变?

@cncolder
Copy link
Contributor

@cncolder cncolder commented Jun 22, 2020

页面配置目前是按小程序的规则生成 json, 但是小程序不允许 require json. 要想在代码中获取配置需要自己导入 import pageConfig from './page.config.js'

app.config.js 的内容是在编译阶段注入到 Current.app.config 的, 同时还有个隐藏变量 window.__taroAppConfig.

页面如果也采用类似的方法, 应该是放在 Current.page.config 上更合适, 包装成 hook 也简单, 事实上 Taro.useRouter 这个 hook 就是对 Current.router 的包装.

@Songkeys
Copy link
Contributor Author

@Songkeys Songkeys commented Jun 22, 2020

要想在代码中获取配置需要自己导入 import pageConfig from './page.config.js'

是的,但是想抽象成 hooks 让所有页面都可以用,没办法引入动态路径。

我也是觉得应该可以跟 app.config 一样在编译时注入。

@yuche yuche added the taro next label Jun 22, 2020
@yuche yuche added this to the 3.0.0-rc.6 milestone Jun 22, 2020
@Chen-jj Chen-jj added enhancement and removed 微信小程序 labels Jun 23, 2020
@yuche yuche modified the milestones: 3.0.0-rc.6, 3.0.0 Jun 23, 2020
@Chen-jj Chen-jj modified the milestones: 3.0.0, 3.0.1, 3.0.2 Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.