uniapp中自定义组件,报错:If this is a native custom element, make sure to exclude it from component.经检查没有符合easycom的规则,即components/组件名称/组件名称.vue 目录结构.

通过uni-app的easycom: 将组件引入精简为一步。只要组件安装在项目的 components 目录下,并符合 components/组件名称/组件名称.vue 目录结构。(在components目录右键----新建组件)

就可以不用引用、注册,直接在页面中使用。   

 <!-- 在index.vue引入 uni-badge 组件-->
    <template>
        <view>
            <uni-badge text="1"></uni-badge><!-- 3.使用组件 -->
        </view>
    </template>
    <script>
        // 这里不用import引入,也不需要在components内注册uni-badge组件。template里就可以直接用
        export default {
            data() {
                return {
                }
            }
        }
    </script>

 easycom是自动开启的,不需要手动开启,有需求时可以在 pages.json 的 easycom 节点进行个性化设置,详见。

不管components目录下安装了多少组件,easycom打包后会自动剔除没有使用的组件,对组件库的使用尤为友好。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐