一.组件定义使用
一.vue组件
1.在项目的/component
目录下存放组件,在要显示组件的页面中则分为3步:导入
、注册
和使用
。例:
<template>
<view>
<myinput></myinput> <!-- 第三步,使用组件 -->
</view>
</template>
<script>
import myinput from "../../components/myinput/myinput.vue" //第一步,导入组件
export default {
components: {
myinput //第二步,注册组件
}
}
</script>
2.2.5.0+
版本支持在pages.json
内引入组件
(easycom
组件模式)
只要组件安装在项目的components
目录下,并符合components/组件名称/组件名称.vue目录结构
,就可以不用引用、注册,直接在页面中使用。 例:
<template>
<view>
<uni-list>
<uni-list-item title="第一行"></uni-list-item>
<uni-list-item title="第二行"&g