概述
微信小程序页面、组件增强方法。提供 computed,watch,mixins 等功能。
安装
clone 项目,将mp-plus.js
放到你的小程序项目里。使用 mp-plus 提供的 api 代替原生页面、组件注册方法。
注册 Page
; ;
注册 Component
; ;
特性
计算属性和侦听器
仿照vue
的风格实现的computed
和watch
示例
; ;
方法合并
小程序原生Page
的方法放在配置项的根层级下,和页面事件方法混在一起难以阅读。mp-plus
仿照vue
的风格将方法全部收集到了methods
字段里。
示例
; ;
mixin
混入 参考vue
的mixin
机制,在Page
和Component
之间实现复用的方式。
为什么不使用
Component
原生的behaviors
?behaviors
只能给组件使用,且不能复用自定义的computed
和watch
。
示例
// myMixin.js data: a: 1 computed: { return thisdataa + 1; } ; // index.js;;; // componentA.js;;;