梗概
- 只要组件安装在项目的components目录下或
uni_modules目录下,并符合components/组件名称/组件名称.(vue|uvue)目录结构
示例
比如前述举例的uni-rate组件,它导入到uni-app项目后,存放在了目录/components/uni-rate/uni-rate.vue 同时它的组件名称也叫uni-rate,所以这样的组件,不用在script里注册和引用。 如下:
<template>
<view>
<uni-rate></uni-rate><!-- 这里会显示一个五角星,并且点击后会自动亮星 -->
</view>
</template>
<script>
// 这里不用import引入,也不需要在components内注册uni-list组件。template里就可以直接用
export default {
data() {
return {
}
}
}
</script>不管components目录下安装了多少组件,easycom打包后会自动剔除没有使用的组件,对组件库的使用尤为友好。