NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[自定义组件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) [TOC] # behavior > 用于组件间代码共享的特性 ## 相同的属性 ``` var common = Behavior({ properties:{ title:String, content:String, src:String } }) export {common}; ``` ## 引用 ``` import {common} from "../common" Component({ behaviors:[common] }) ``` # 重点 ## 子组件向父组件传参 ``` var behavior = this.data.isLike; this.triggerEvent('isLike',{ behavior }) ``` ## 父组件接受 ``` <v-like like="{{like}}" count="{{count}}" bind:isLike="onLike"></v-like> //获取组件中的传值 onLike(e) { var behavior = e.detail.behavior; }, ``` ## attached() > //当组件触发 attached 生命周期时,会依次触发 my-behavior 中的 attached 生命周期函数和 my-component 中的 attached 生命周期函数