日期: 2026-05-05
控制台报错:
Invalid regular expression: /[\p{L}\p{N}]/: Invalid property name in character class
marked 包 v10+ 使用了 Unicode 属性转义正则表达式(如 /\p{L}\p{N}/u),App 基座的旧版 JS 引擎不支持。
降级 marked 到旧版本:
npm install marked@4.3.0 --legacy-peer-deps
日期: 2026-05-05
App 启动时提示:
本应用使用HBuilderX4.84或对应的cli版本编译,而手机端SDK版本是5.07
cli 项目的编译器版本与 HBuilderX 版本不同步,需要手动升级编译器。
npm install @dcloudio/uni-app@latest --legacy-peer-deps
# 或指定版本
npm install @dcloudio/uni-app@3.0.0-alpha-5000720260416001 --legacy-peer-deps
升级后验证:
npm list @dcloudio/uni-app
npm update @dcloudio/uni-app 保持编译器最新日期: 2026-05-05
App 没有任何网络请求,接口没调用。
config.ts 中 getPlatform() 获取的平台名为首字母大写(如 Android),而配置对象用的是小写(android)undefined修复 config.ts 中的平台判断:
function getPlatform(): 'web' | 'android' | 'ios' | 'h5' {
// #ifdef APP-PLUS
const systemInfo = uni.getSystemInfoSync();
const platform = (systemInfo.platform || '').toLowerCase();
if (platform === 'android') return 'android';
if (platform === 'ios') return 'ios';
return 'android';
// #endif
return 'web';
}
my-uniapp-vue3/src/utils/config.ts日期: 2026-05-05
player/index.vue - window.location.href 和 window.location.origin
// #ifdef H5 / // #ifndef H5book-generator/index.vue - new URL(), window.location.hash, history.pushState
payment-confirm/index.vue - window.location.origin
NetworkStatus.vue - window.addEventListener
uni.onNetworkStatusChange APIrequest.ts - require() 动态导入
import 静态导入| API | H5 | App | 替代方案 |
|---|---|---|---|
window.location |
✅ | ❌ | 条件编译 |
document.createElement |
✅ | ❌ | 条件编译 |
localStorage |
✅ | ❌ | uni.getStorageSync |
navigator.share |
✅ | ❌ | uni.share |
history.pushState |
✅ | ❌ | 条件编译 |
new URL() |
✅ | ❌ | 条件编译 |
所有使用 H5 特有 API 的地方,都应该使用条件编译:
// #ifdef H5
// H5 专用代码
// #endif
// #ifndef H5
// App/小程序 专用代码
// #endif
日期: 2026-05-05
App 页面报错:TypeError: Converting circular structure to JSON
getCurrentPages() 返回的页面对象包含循环引用($vm 属性),不能直接用 JSON.stringify() 序列化。
避免对页面对象使用 JSON.stringify:
// 错误 ❌
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
console.log(JSON.stringify(currentPage)); // 会崩溃!
// 正确 ✅
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1] as any;
const id = currentPage?.options?.id; // 直接访问属性
player/index.vue - 移除 JSON.stringify(currentPage)日期: 2026-05-05
播放器页面在 App 上布局错乱,很多元素重叠或位置不对。
App 基座不支持 CSS gap 属性。
使用 margin 替代 gap:
/* 错误 ❌ */
.container {
display: flex;
gap: 16rpx;
}
/* 正确 ✅ */
.container {
display: flex;
}
.container > view {
margin-right: 16rpx;
}
player/index.vue - 所有 gap 改用 margin开发时使用 H5 测试,但发布前务必在 App 真机上测试布局。