Closed b2nil closed 3 years ago
暂时通过 58bb20faea5f16a54051da02ea24f3cc15021d4f 解决。
将项目编译成 h5,需要进行如下配置:
在项目的 config
目录下增加一个 h5 构建脚本: h5-building-script.js
将 package.json
下的 build:h5
命令修改为:
"build:h5": "node ./config/h5-building-script.js && taro build --type h5",
在 config/index.js
中的 h5
下添加 webpack alias 设置:
webpackChain(chain) {
chain.resolve.alias
.set('@tarojs/components$', path.resolve(__dirname, '..','node_modules/@tarojs/components/dist-h5/vue3/index.js'))
.set('@tarojs/components/dist/taro-components/taro-components.css', path.resolve(__dirname, '..','node_modules/@tarojs/components/dist/taro-components/taro-components.css'))
}
编译至 h5, 不能直接使用渲染函数渲染 Taro 组件标签,而是需要使用 resolveComponent
先将标签解析为组件,然后再渲染:
import { resolveComponent } from 'vue'
h('taro-view') // 错误
h(resolveComponent('taro-view')) // 正确
编译到 h5 后,点击部分监听事件的
taro-xxx-core
组件后,组件样式会被设置为visibility: hidden
。 受影响的组件包括:AtCalendar
,AtCheckBox
等等……