白羽
白羽
  • 发布:2020-01-15 15:48
  • 更新:2020-03-09 19:48
  • 阅读:3870

【报Bug】2.5.1(v3)编译含有递归组件的uniapp报错,getApp is not defined...

分类:uni-app

我在在2.5.1版本下编译含有递归组件的项目,经测试:
1.在非v3版本下,编译正常,且可以多端运行。

  1. 切换至v3版本,编译通过,但立即显示大量且重复的错误信息:getApp is not defined...
  2. 我测试了v3下的以下5个选项的全部25种组合,皆如此:
  • 重启HX

  • v3编译器

  • fast启动模式

  • 发生时启用摇树优化

  • 去掉pages.json/globalStyle中的组件页

    
    {  
    "path" : "components/qiu-holotext/qiu-holotext",  
    "style" : {}  
    }  
  • 去掉pages.json/globalStyle中的

    "usingComponents": {  
    "qiu-holotext": "/components/qiu-holotext/qiu-holotext"  
    }

报错信息如下:
[广告] 15:42:35.261 开源不易,需要鼓励。去给 uni-app 项目 点个 star 吧 [不再提示]
[广告] 15:42:35.261 DCloud 新春招聘开启,欢迎前端、Android、C++/QT来投简历! 详情点击
15:42:35.328 项目 'qiu-holotext' 开始编译...
15:42:37.543 编译器版本:2.5.1(v3)详见:https://ask.dcloud.net.cn/article/36599。
15:42:37.552 请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
15:42:37.552 正在编译中...
15:42:43.326 DONE Build complete. Watching for changes...
15:42:43.328 项目 'qiu-holotext' 编译成功.
15:42:43.727 正在建立手机连接...
15:42:46.283 正在同步手机端程序文件...
15:42:46.656 同步手机端程序文件完成
15:42:47.759 正在启动HBuilder调试基座...
15:42:50.057 应用【qiu-holotext】已启动...
15:42:50.555 App Launch at App.vue:4
15:42:50.576 App Show at App.vue:7
15:42:51.345 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.365 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.385 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.406 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.427 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.447 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.468 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.489 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.510 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.531 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.551 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.572 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.594 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.613 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.635 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.654 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.674 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.695 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.716 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.737 TypeError: Cannot read property 'type' of undefined at view.umd.min.js:6
15:42:51.757 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.779 TypeError: a.matches is not a function at view.umd.min.js:6
15:42:51.799 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.819 TypeError: a.matches is not a function at view.umd.min.js:6
15:42:51.842 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.861 Error: Not Found:Page[1][680b3210] at view.umd.min.js:6
15:42:51.883 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.903 Error: Not Found:Page[1][fc06b377] at view.umd.min.js:6
15:42:51.923 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.945 Error: Not Found:Page[1][611cc36b] at view.umd.min.js:6
15:42:51.965 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:51.985 Error: Not Found:Page[1][b950f1d2] at view.umd.min.js:6
15:42:52.007 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.027 Error: Not Found:Page[1][2c0e51f2] at view.umd.min.js:6
15:42:52.048 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.069 Error: Not Found:Page[1][d710ba66] at view.umd.min.js:6
15:42:52.090 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.110 Error: Not Found:Page[1][a8e4f604] at view.umd.min.js:6
15:42:52.131 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.152 Error: Not Found:Page[1][47647a61] at view.umd.min.js:6
15:42:52.173 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.194 Error: Not Found:Page[1][ec26b7cf] at view.umd.min.js:6
15:42:52.215 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.235 Error: Not Found:Page[1][7218655a] at view.umd.min.js:6
15:42:52.256 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.277 Error: Not Found:Page[1][244bd975] at view.umd.min.js:6
15:42:52.298 ReferenceError: getApp is not defined at view.umd.min.js:6
15:42:52.319 Error: Not Found:Page[1][019bc8b6] at view.umd.min.js:6

2020-01-15 15:48 负责人:无 分享
已邀请:
白羽

白羽 (作者)

补充控制台信息。

DCloud_UNI_FXY

DCloud_UNI_FXY

qiu-holotext 是小程序组件?贴一下这个组件的代码

  • 白羽 (作者)

    好的。请参见下一条回复。

    2020-01-15 16:24

白羽

白羽 (作者)

补充代码。非v3版本下,在APP、小程序和H5都能正确运行。
以下是普通的组件代码;

<template>  
    <!-- 数组 -->  
    <view v-if="Object.prototype.toString.call(content) === '[object Array]'">  
        <qiu-holotext v-for="(child, index) in content" :content="child" :key="index"></qiu-holotext>  
    </view>  
    <!-- 文本 -->  
    <text v-else-if="Object.prototype.toString.call(content) === '[object String]'">{{content}}</text>  
    <text v-else-if="Object.prototype.toString.call(content) === '[object Object]' && Object.prototype.toString.call(content.value) === '[object String]' && (content.type === undefined || content.type === 'text')">{{content.value}}</text>  
</template>  
<script>  
    let that = [];  
    export default {  
        name: 'qiu-holotext',  
        props: ['content'],  
        data() {  
            return {  
            };  
        }  
</script>  
<style>  
</style>

以下是index页的调用代码:

<template>  
    <view class="content" style="font-size: 14px;">  
        <qiu-holotext :content="content"></qiu-holotext>  
    </view>  
</template>  
<script>  
    import qiuHolotext from "@/components/qiu-holotext/qiu-holotext.vue"  
    export default {  
        components: {  
            qiuHolotext  
        },  
        data() {  
            return {  
                content: [  
                '基本原理',  
                {  
                    type: 'text',  
                    value: 'ddd'  
                }]  
            }  
        }  
    }  
</script>

以下是pages.json页配置

{  
    "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages  
        {  
            "path": "pages/index/index",  
            "style": {  
                "navigationBarTitleText": "uni-app"  
            }  
        }  
        ,{  
            "path" : "components/qiu-holotext/qiu-holotext",  
            "style" : {}  
        }  
    ],  
    "globalStyle": {  
        "navigationBarTextStyle": "black",  
        "navigationBarTitleText": "uni-app",  
        "navigationBarBackgroundColor": "#F8F8F8",  
        "backgroundColor": "#F8F8F8",  
        "usingComponents": {  
            "qiu-holotext": "/components/qiu-holotext/qiu-holotext"  
        }  
    }  
}
DCloud_UNI_FXY

DCloud_UNI_FXY

你给的代码有问题,无限循环了
你可以给qiu-holotext增加name选项实现递归组件
详情参考:https://cn.vuejs.org/v2/guide/components-edge-cases.html#递归组件

  • 白羽 (作者)

    1.原代码已经添加有name选项;

    2.已核实没有出现无限循环问题;

    3.原代码可以在非V3版本下的Android/iOS/微信小程序/H5中工作;

    4.且原代码单纯地切换到v3之后,仍可以在微信小程序/H5中工作,但不能在APP端工作。


    所以我有理由猜测,不是代码出了问题,而是v3的APP端不支持递归组件。不知道我的理解对不对呢?


    假若确实是v3不支持APP端的递归组件,那么官方有什么开发计划吗?或者,有什么样的绕过的方案吗?


    假如V3是支持APP端组件的,应当怎样设置,才能使用递归组件呢?


    望告知,非常非常感谢!

    2020-01-27 03:35

  • 白羽 (作者)

    另外,我还发现了另一个bug:


    非V3版本新建的的uniapp项目,当切换为v3版本并重启HX后,HX端的vue页面的所有中文都会变成乱码;如果强行修改为正常中文,则APP端的中文就会变成乱码。反向操作亦然。感觉v3和非v3采用了不同的编码方案。

    2020-01-27 03:44

  • DCloud_UNI_FXY

    回复 白羽: 发一个完整的可重现该问题的demo工程出来吧

    2020-02-04 14:48

  • yorick

    回复 DCloud_UNI_FXY: 同样遇到问题 安卓会有闪退 所以启用了v3 也是报这些错误

    2020-02-05 21:58

  • DCloud_UNI_FXY

    回复 yorick: 需要一个可重现该问题的demo工程,才好排查问题

    2020-02-06 00:51

  • yorick

    回复 DCloud_UNI_FXY: 我抽空整理一下

    2020-02-06 13:44

  • yorick

    回复 DCloud_UNI_FXY: 已经上传了demo https://ask.dcloud.net.cn/question/88486

    2020-02-06 16:06

  • 白羽 (作者)

    回复 DCloud_UNI_FXY: https://ext.dcloud.net.cn/plugin?id=1243


    抱歉啊,今天没有登社区。我在插件市场上传的轻量级uniapp数学公式组件,有一个示例项目。非v3版能够编译,切换至V3编译,就会出现上述问题。麻烦您看看哈!

    2020-02-06 22:31

  • 白羽 (作者)

    回复 DCloud_UNI_FXY: 另外,我重写了递归组件,将v-if表达式全部换成computed属性值之后,v3编译不再出现上述报错,但同时APP端也未渲染递归组件的内容。H5端始终是正常的。

    2020-02-06 22:38

  • DCloud_UNI_FXY

    回复 白羽: 该bug已修复,下次发版会带上

    2020-02-08 23:33

  • 白羽 (作者)

    回复 DCloud_UNI_FXY: 感谢!辛苦了!

    2020-02-09 02:28

  • 白羽 (作者)

    回复 DCloud_UNI_FXY: 刚刚升级了HX2.6.0(V3),依然不支持递归组件。

    2020-02-25 17:07

  • DCloud_UNI_FXY

    回复 白羽: 下一个alpha版本支持

    2020-02-25 18:33

  • 白羽 (作者)

    回复 DCloud_UNI_FXY: 期待。这功能太重要了。官方加油!

    2020-02-25 18:40

  • 2***@qq.com

    回复 DCloud_UNI_FXY: 这个问题,V3模式之下,我也出现了很多,更新到2.6.1版本,还是有这个问题,安卓很卡,急需V3,希望能尽快修复

    2020-02-29 17:36

v***@qq.com

v***@qq.com - 蓝牙

也遇到问题了,找了半天,看了这个帖子终于恍然。

米虫

米虫

楼主的问题怎么解决的我也报错
打包app白屏 后台调试发现包下面的错误
12:39:14.424 ReferenceError: getApp is not defined at view.umd.min.js:6
12:39:14.444 TypeError: Cannot read property '_$g' of undefined at view.umd.min.js:6

DCloud_UNI_FXY

DCloud_UNI_FXY

HBuilderX 2.6.3 Alpha 已修复

  • 白羽 (作者)

    已核实HX 2.63 V3 Alpha支持递归组件,并且运行速度大幅提升,感谢!

    2020-03-11 16:02

该问题目前已经被锁定, 无法添加新回复