大明子
大明子
  • 发布:2023-04-21 19:42
  • 更新:2023-04-23 16:14
  • 阅读:851

【报Bug】使用easycom组件后,与component组件冲突

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 11 专业版 22H2

HBuilderX类型: 正式

HBuilderX版本号: 3.7.9

手机系统: Android

手机系统版本号: Android 12

手机厂商: 小米

手机机型: 小米10

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
 <template>  
    <view class="content">  
        <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"  
            activeColor="#4cd964"></uni-segmented-control>  
        <view class="content">  
            <view v-for="(tab,idx) in items" :key="idx">  
                <component :is="getComponentName(tab)" />  
            </view>  
        </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                items: ['组件A', '组件B', '组件C'],  
                current: 0  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            onClickItem(e) {  
                if (this.current != e.currentIndex) {  
                    this.current = e.currentIndex;  
                }  
            },  
            //获取自定义组件  
            getComponentName(tab) {  
                switch (tab) {  
                    case '组件A':  
                        return 'test-a'  
                    case '组件B':  
                        return 'test-b'  
                    case '组件C':  
                        return 'test-c'  
                    default:  
                        return 'test-empty' // 如果找不到对应的组件,则使用默认组件  
                }  
            }  
        }  
    }  
</script>  

<style>  
    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>
{  
    "easycom": {  
        "autoscan": true,  
        "custom": {  
            "^test-(.*)": "@/components/test/test-$1/index.nvue"  
        }  
    }  
}

操作步骤:

直接使用附件中的demo

预期结果:

直接使用附件中的demo

实际结果:

直接使用附件中的demo

bug描述:

我这边的场景是需要动态加载组件,所以使用到了component ,由于动态加载,就决定使用easycom,这样就不用每个组件都声明引入了,但是发现 component 并不能直接加载未经引入声明的组件。

2023-04-21 19:42 负责人:无 分享
已邀请:
YUANRJ

YUANRJ

看下easycom的注意事项 文档

easycom只处理vue组件,不处理小程序专用组件(如微信的wxml格式组件)。不处理后缀为.nvue的组件。但vue组件也可以全端运行,包括小程序和app-nvue。可以参考uni ui,使用vue后缀,同时兼容nvue页面。

  • 大明子 (作者)

    请查看我的demo, easycom加载成功后, 不能在component 使用。这个是问题所在。

    2023-04-24 10:08

要回复问题请先登录注册