uni-app 小程序发行后页面组件路径错误

uni-app 小程序发行后页面组件路径错误

开发环境 版本号 项目创建方式
Windows win10 pro 19042.868 HBuilderX
### 操作步骤:
- 使用HbuilderX发行微信小程序

### 预期结果:
```json
"usingComponents": {
"bar": "../../components/bar",
"top-bar": "../../components/topTab",
"min-swiper": "../../components/minSwiper"
}

实际结果:

"usingComponents": {
"bar": "..\..\components\bar",
"top-bar": "..\..\components\topTab",
"min-swiper": "..\..\components\minSwiper"
}

bug描述:

小程序发行后页面组件路径配置那里的 / 全部变成了
导致页面报错Cannot read property ‘$vm’ of undefined 以及找不到相关组件


更多关于uni-app 小程序发行后页面组件路径错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app 小程序发行后页面组件路径错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是典型的 Windows 路径分隔符问题。在 Windows 系统中,HBuilderX 发行小程序时,路径分隔符被错误地转换为了反斜杠 \,而小程序平台要求使用正斜杠 /

解决方案:

  1. 检查 manifest.json 配置: 确保 src/manifest.json 中的小程序配置正确:

    "mp-weixin": {
      "usingComponents": true
    }
    
  2. 检查组件引用方式: 在页面中正确引用组件:

    <template>
      <bar />
    </template>
    
    <script>
    export default {
      components: {
        bar: () => import('@/components/bar.vue')
      }
    }
    </script>
    
  3. 使用绝对路径: 在 pages.json 中配置组件时使用绝对路径:

    {
      "easycom": {
        "autoscan": true,
        "custom": {
          "^@/components/(.*)": "@/components/$1"
        }
      }
    }
回到顶部