HBuilder X3.4版本中使用uni-app自定义组件

HBuilder X3.4版本中使用uni-app自定义组件

这是我的小程序页面结构
在这里插入图片描述

方式一:导入components

1.创建componets文件,并编写你的组件页面
在这里插入图片描述

<template>
  <view class="my-search-container">
    <!-- 使用 view 组件模拟 input 输入框的样式 -->
    <view class="my-search-box">
      <uni-icons type="search" size="17"></uni-icons>
      <text class="placeholder">搜索</text>
    </view>
  </view>
</template>

2.使用页面import导入和注册组件

<script>
  import MySearch from '@/componets/my-search/my-search.vue'
  export default {
    //组件
    components:{MySearch},
 }
</script>

3.使用组件

<template>
  <view>
    <MySearch></MySearch>
  </view>  
</template>
  

方式二:easycom配置

1.在uni_modules下,路径为uni_modules/插件ID/components/组件名称/组件名称.vue

在这里插入图片描述

2.在pages.json文件中,设置easycom参数

"easycom": {
  "autoscan": true,
  "custom": {
    "^uni-(.*)": "@/components/uni-$1.vue", // 匹配components目录内的vue文件
    "^vue-file-(.*)": "packageName/path/to/vue-file-$1.vue" // 匹配node_modules内的vue文件
  }
}

更多细节链接:

https://en.uniapp.dcloud.io/component/ 
https://en.uniapp.dcloud.io/collocation/pages.html#easycom
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值