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

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

这是我的小程序页面结构

方式一:导入components

1.创建componets文件,并编写你的组件页面

vue 复制代码
<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导入和注册组件

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

3.使用组件

vue 复制代码
<template>
  <view>
    <MySearch></MySearch>
  </view>  
</template>
  

方式二:easycom配置

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

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

json 复制代码
"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
相关推荐
2501_916007473 小时前
iOS 证书如何创建,从能生成到能长期使用
android·macos·ios·小程序·uni-app·cocoa·iphone
00后程序员张6 小时前
AppStoreInfo.plist 在苹果上架流程中的生成方式和作用
android·小程序·https·uni-app·iphone·webview
2501_915106327 小时前
iOS App 测试方法,通过 Xcode、Instruments、Safari Inspector、克魔(KeyMob)等工具
android·ios·小程序·uni-app·iphone·xcode·safari
游戏开发爱好者88 小时前
对 iOS IPA 文件进行深度混淆的一种实现路径
android·ios·小程序·https·uni-app·iphone·webview
百锦再9 小时前
UniApp与UniApp X:跨平台开发的范式革命与全面技术解析
服务器·ai·uni-app·k8s·core·net
Change!!9 小时前
uniapp写的h5,怎么根据页面详情,设置不同的标题
前端·uni-app·标题
2501_916007479 小时前
Xcode 在 iOS 上架中的定位,多工具组合
android·macos·ios·小程序·uni-app·iphone·xcode
浅箬9 小时前
uniapp 打包之后出现shadow-grey.png去除
前端·uni-app
游戏开发爱好者89 小时前
uni-app 项目在 iOS 上架过程中常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
2501_915106329 小时前
iOS 抓包工具在不同场景的实际作用
android·macos·ios·小程序·uni-app·cocoa·iphone