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

相关推荐

  1. uni-app 定义tabbar

    2024-07-17 14:24:03       30 阅读
  2. vue使用定义组件规则

    2024-07-17 14:24:03       34 阅读
  3. uni-app怎样使用组件

    2024-07-17 14:24:03       22 阅读
  4. uni-app组件和样式的使用

    2024-07-17 14:24:03       41 阅读
  5. uni-app定义tabbar(van-tabbar)

    2024-07-17 14:24:03       47 阅读
  6. Vue定义组件使用CSS变量设置样式?

    2024-07-17 14:24:03       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 14:24:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 14:24:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 14:24:03       58 阅读
  4. Python语言-面向对象

    2024-07-17 14:24:03       69 阅读

热门阅读

  1. 3 万字 25 道 Nginx经典面试题总结

    2024-07-17 14:24:03       21 阅读
  2. 翁恺-C语言程序设计-10-0. 说反话

    2024-07-17 14:24:03       15 阅读
  3. MVC、MVP和MVVM这三种设计模式的区别

    2024-07-17 14:24:03       25 阅读
  4. SCP 使用教程

    2024-07-17 14:24:03       29 阅读
  5. 【微信】签名生成-用户态签名

    2024-07-17 14:24:03       25 阅读
  6. 创建React项目:使用 create-react-app 创建 React 应用

    2024-07-17 14:24:03       19 阅读
  7. 【多线程】线程安全的单例模式

    2024-07-17 14:24:03       22 阅读
  8. 什么是区块链

    2024-07-17 14:24:03       23 阅读
  9. 速盾:ddos高防ip哪里好用?

    2024-07-17 14:24:03       25 阅读
  10. Feign客户端是什么,它跟Ribbon有什么区别?

    2024-07-17 14:24:03       22 阅读