1.1什么是behaviors
![](https://img-blog.csdnimg.cn/img_convert/5a8acbbb266e46cf1906e7eb77e4c699.png)
1.2behaviors的工作方式
![](https://img-blog.csdnimg.cn/img_convert/bb3b14ee7a06b99fb4854307130ad253.png)
1.3如何创建behaviors
步骤一:在微信小程序中创建behaviors文件,并在文件中创建mybehaviors.js文件
注意:名称自定义,但尽量符合相关规范
![](https://img-blog.csdnimg.cn/img_convert/bbdead176023b5763b0096990d9a135a.png)
步骤二:在mybehaviors.js文件中编写对应代码
//将behaviors导出
module.exports =Behavior({
//偏向私有数据
data:{
},
//偏向外部传入数据
properties:{
},
methods:{
}
})
1.4如何导入和使用behaviors
![](https://img-blog.csdnimg.cn/img_convert/b1e2811fa33ebcfa121786543c2e1335.png)
1.5behaviors中一些可用的节点
![](https://img-blog.csdnimg.cn/img_convert/a6e0d555bb560203439fc49dd098c689.png)
1.6组件与behaviors字段重名问题的三种解决方案
具体参考微信小程序官方文档
![](https://img-blog.csdnimg.cn/img_convert/3958c31ccdf3b5d2206cfe2e132a2d47.png)