MBTI小程序适配H5和微信小程序之改造与踩坑

省流版:最多改一下第一点就可以适配了,如果按照皮总的做并且没加其他任何东西的话,issues区有人提到这个问题也会在近期的版本中修复。


1、编译到H5的启动命令是:npm run build:h5 -- --watch

启动完就会发现有个warning(借用一下github issues区老哥的图)

Compiled with problems:X

WARNING in external "taro_app_library@/remoteEntry.js"

The generated code contains 'async/await' because this module is using "external script".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.

解决方案就是:在config/index.ts中改一下compiler。

compiler: {
prebundle: {
enable: false,
},
type: 'webpack5'
},

github issues区说是在src下的config/index.ts,但是我看了一下我自己的项目目录,发现没有,我的config文件在这里。


附上github issues的地址:https://github.com/NervJS/taro/issues/15413


2、我发现我前几天写bug了

主页这里我类名没有跟着皮总额外加一个类名,而是直接改了at-article__h1和at-article__h2的样式,导致小程序没问题但是H5跳转到题目页面的时候title显示不出来了!!!(因为在主页把文字颜色设置成了白色),然后也没有任何报错,后续F12点标题那块发现的,哭笑不得。

前几天发的帖子也更新了:https://articles.zsxq.com/id_dkr7ixqwgk50.html

3、H5不支持hideHomeButton。然后条件编译的方式跟uni-app不一样,Taro官方说可以这么写

if (process.env.TARO_ENV === 'weapp') {
setTimeout(() => { // 使用延时,避免隐藏不生效
Taro.hideHomeButton()
}, 200);
}

也可以这么写

{ process.env.TARO_ENV === 'weapp' &&
setTimeout(() => { // 使用延时,避免隐藏不生效
Taro.hideHomeButton()
}, 200);
}

Taro文档地址:https://taro-docs.jd.com/docs/envs


0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
昕笙
下载 APP