uniapp 报警告 If this is a native custom element,的问题

2,482 阅读1分钟

If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement

问题分析

该警告说明在模板中使用了一个无法自动识别的标签。 可能的原因有:

  1. 因为手误写错了,这个要自己仔细检查

  2. 使用了自定义组件/第三组件

问题解决方案

  1. 如果是第一点原因,自己仔细检查拼写错误即可

  2. 如果是这一点,放在vue中一般是没有在页面中注册导致 导入、注册、使用,缺一不可。

	<!-- 在index.vue引入 uni-badge 组件-->
	<template>
		<view>
			<uni-badge text="1"></uni-badge><!-- 3.使用组件 -->
		</view>
	</template>
	<script>
		import uniBadge from '@/components/uni-badge/uni-badge.vue';//1.导入组件(这步属于传统vue规范,但在uni-app的easycom下可以省略这步)
		export default {
			components:{uniBadge }//2.注册组件(这步属于传统vue规范,但在uni-app的easycom下可以省略这步) 
		}
	</script>

但是在uniapp中有自动导入机制,只要按需使用即可,easycom会自动导入注册,按照官方的组件目录放置自定义组件。

	│─components            	符合vue组件规范的uni-app组件目录
	│  └─componentA         	符合‘components/组件名称/组件名称.vue’目录结构,easycom方式可直接使用组件
	│  		└─componentA.vue    可复用的componentA组件
	│  └─component-a.vue      可复用的component-a组件

放置准确后,是最重要的一步,检查easycom是否开启了 在pages.json文件中搜索easycom,查看是否有配置项,没有的话就添加进去,

"easycom": {
  "autoscan": true
}