2024-08-27 10:08:47 +08:00

42 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自定义组件
关于自定义组件https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/
在使用自定义组件的时候,首先需要注意版本问题,基础库要大于等于 1.6.3
在使用自定义组件的时候,一般单独拿一个目录来存放自定义组件,一般是 components
页面中在使用自定义组件时,需要在在 json 文件中进行一个配置,例如:
```js
{
"usingComponents": {
"item" : "/components/item/item"
}
}
```
不同于页面对应的 JS 文件中的 Page 构造器,在自定义组件中,对应的 JS 文件的构造器为 Component
- properties在使用自定义组件时父组件传入的属性
- data表示该自定义组件自身的数据
- methods书写对应的事件处理函数
- options: 关于自定义组件的选项配置,例如我们要使用多插槽的时候,就需要配置 multipleSlots 为 true
- externalClasses用于指定外部传入的样式类
从开发者工具 1.02.1810190 及以上版本开始,可以在 app.json 中使用 usingComponents 来注册组件,在 app.json 中所注册的组件被视为全局组件,各个页面,以及其他自定义组件中都可以使用。
在设计自定义组件的时候,是可以添加插槽,插槽的用法和 Vue 是非常类似的。
并且和 Vue 中的插槽一样,可以设置具名插槽