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] 提供扩展预渲染的能力 #6488

Closed
charmtiger opened this issue May 28, 2020 · 7 comments
Closed

[Taro Next] 提供扩展预渲染的能力 #6488

charmtiger opened this issue May 28, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@charmtiger
Copy link

charmtiger commented May 28, 2020

问题描述

预渲染 的时候,自定义 header 要使用变量(状态栏高度),但是编译出来的是缺省值,所以进入页面的时候,总是要顶一下整个页面,有没有优化技巧。

比如这样,但是这样写挺生硬的,最好可以在组件文件内实现。

mini: {
    prerender: {
      match: 'pages/witManhole/**',
      console: true,
      transformData (data, { path }) {
        if (path === 'pages/witManhole/witManhole') {
          data.cn[0].cn[0].cn[0].cn[0].st = 'height: {{global.statusBarHeight}}px'
          return data
        }
        return data
      }
    }
}

动图 如果看不完整 请点击在新的窗口打开
image

@Chen-jj Chen-jj added enhancement New feature or request P-2 Medium, minor/patch and removed taro next labels Jul 2, 2020
@taro-bot taro-bot bot modified the milestone: 3.1.0 Jul 2, 2020
@Chen-jj Chen-jj removed this from the 3.1.0 milestone Jul 10, 2020
@Chen-jj Chen-jj removed the P-2 Medium, minor/patch label Jul 10, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 10, 2020

假设状态栏高度是动态获取的,预渲染时并不能知道应该取什么值,感觉这里应该可以通过给一个默认值解决吧。

@Chen-jj Chen-jj closed this as completed Jul 10, 2020
@charmtiger
Copy link
Author

预渲染的时候不渲染具体的值,把特定的位置,如 height: {小程序原生全局变量 },这个变量预渲染时不是已有的值,而是代码字符串,只是不确定 wxml 中能否访问小程序全局变量。

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 13, 2020

不行的,视图层不能访问逻辑层全局变量

@charmtiger
Copy link
Author

这种情况能否使用 小程序原生组件 来实现呢?预编译的时候 应该没把这个编译进来吧

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 13, 2020

什么小程序原生组件,预渲染就是无网络情况下你的 wxml 结构咯

@charmtiger
Copy link
Author

https://taro-docs.jd.com/taro/docs/mini-third-party
预编译的时候,原生组件应该是没有被编译吧,编译出的页面代码,与原生组件是引用关系,逻辑也是独立的,自定义组件内获取状态栏高度,然后把高度给 view,应该可以解决图中问题。刚想到的,我抽空尝试一下先

@allen-hu-666
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants