小程序的组件

152 阅读1分钟

组件的通信

1. component properties

常见的组件开发方式

<toast id='toast' toastFetter='{{toastFetter}}' toastCount="{{toastCount}}"></toast>

同时在JS文件中定义变量就能在组件中通过properties获得传值

组件的事件通过this.triggerEvent()

<component-tag-name bind:myevent="onMyEvent" />

2. template

引用wxml 引用wxss 引用js 处理事件要在父组件的JS中

使用template的模式开发时,要注意文件的应用,JS文件通过module.exports导出

3. selectComponent 获取组件的实例在父组件js执行子组件方法

<toast id='toast' toastFetter='{{toastFetter}}' toastCount="{{toastCount}}"></toast>

JS

this.selectComponent('#toast') 获取组件的实例

组件和页面的生命周期