Component({ properties: { propName: { // 属性名 type: String, // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型) value: 'val', // 属性初始值(必填) observer: function (newVal, oldVal) { // 属性被改变时执行的函数(可选) } } }, data: { isModalShow: false, animationData: '' }, // 私有数据,可用于模版渲染 openModal() { const animation = swan.createAnimation() animation.translateY(-500).step(); this.setData({ isModalShow: true }, () => { this.setData({ animationData: animation.export() }) }) }, closeModal() { const animation = swan.createAnimation() animation.translateY(0).step(); this.setData({ animationData: animation.export()}, () => { setTimeout(()=>{ this.setData({ isModalShow: false, }) clearTimeout },400) }) }, // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { }, detached: function () { }, methods: { onTap: function () { this.setData({ // 更新属性和数据的方法与更新页面数据的方法类似 }); } } });