Skip to content

支持在Component中调用 #20

@SheldonLaw

Description

@SheldonLaw

需求描述

从小程序基础库版本 1.6.3 开始,小程序支持简洁的组件化编程 - 小程序自定义组件,但在Component中引用weSwiper会出现动画失效的问题。

通过阅读源码发现:

weSwiper通过动态修改view中的animation属性来实现动画效果,数据传递是通过page.setData来实现的。这样就导致了在Component里引用weSwiper时,无法得到更新的animation值来实现动画。

image

具体实现

为了实现在Component中引用weSwiper,添加了context参数,使得数据传递是通过context.setData(这里的context是component)来实现的,具体代码如下:

image

讨论

还有没有别方案实现该需求:通过page.setData来改变page的animation属性,再将page中的animation属性传递给component,实现动画。但是破坏了component的封装性。

欢迎讨论,再次感谢你们贡献了这个优秀的组件!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions