搞小程序也有兩周了,踩了很多坑,有些問題很難搜索到,在這里記錄一下問題和自己的解決方案,希望能幫助到需要的小伙伴~
1. 真機調試報錯:Error: module ‘@babel/runtime/helpers/Arrayincludes.js’ is not defined
- 真機調試模式從 2.0 切換為 1.0 即可解決
- 要將【轉換為 ES5】勾選掉,因為 Taro 通過 webpack 已經將代碼編譯為 ES5。
2. Taro 中如何使用 weui?
// app.config.ts
useExtendedLib: { weui: true, },
usingComponents: { 'mp-badge': 'weui-miniprogram/badge/badge'...},
3. Taro 動態設置當前頁面的標題
Taro.setNavigationBarTitle(option)
- 文檔:https://docs.taro.zone/docs/apis/ui/navigation-bar/setNavigationBarTitle
4. app.js錯誤: Error: module ‘common.js’ is not defined, require args is './common’
- 偶現,可以先重啟 webpack
5. 小程序樣式不生效,tailwind 偽類不生效(hover)
- 因為 標簽要單獨配置 hoverClass
- 文檔:https://docs.taro.zone/docs/components/viewContainer/view
6. Error: module ‘vendors.js’ is not defined
- 刪掉 node_modules 重裝
7. fail api scope is not declared in the privacy agreement
- 參考:https://developers.weixin.qq.com/community/develop/article/doc/0006e28bddcdd89ff7208d2e06bc13
8. taro 中配置的 global.d.ts 引入方式不能使用 import,否則因為在頭部引用會導致整個 ts 配置文件失效!
- 正確引入方式:
/// <reference types="@tarojs/taro" />
。因為在頭部錯誤使用 import 引入類型,導致 declare module ‘*.png’ 不生效
9. object-fit 在小程序中不生效
- 內置了字段可以配置,參考:https://docs.taro.zone/docs/components/media/image
10. Taro 引入 weui <mp-dialog>
其中bindbuttontap
按鈕點擊事件不生效
- 需要將
bindbuttontap
改成onButtontap
11. uploadFile:fail createUploadTask:fail url not in domain list
可能有如下原因:
- uploadFile 合法域名未配置或配置錯誤
- 或者是 url 寫錯(仔細檢查一下,我這邊就是 url 傳錯了,忘記添加 baseurl,因為和 get 與 post一起封裝的,但是options沒有共用)
12. Taro 如何實現手勢放縮圖片
- 注意需要配置 scale 才支持放縮
<MovableArea style='height: 200px; width: 200px; background: red;'><MovableView style='height: 50px; width: 50px; background: blue;' direction='all' scale ></MovableView>
</MovableArea>
13. 小程序使用 <mp-dialog>
時彈窗被鍵盤遮住
- 配置 input 組件
cursor-spacing
參數,可以指定光標與鍵盤的距離