UNPKG

wux-weapp

Version:

一套组件化、可复用、易扩展的微信小程序 UI 组件库

48 lines (46 loc) 1.4 kB
import baseComponent from '../helpers/baseComponent' import classNames from '../helpers/libs/classNames' baseComponent({ relations: { '../timeline-item/index': { type: 'child', observer() { this.callDebounceFn(this.updateIsLastElement) }, }, }, properties: { prefixCls: { type: String, value: 'wux-timeline', }, pending: { type: Boolean, value: false, }, position: { type: String, value: 'left', }, }, methods: { updateIsLastElement() { const elements = this.getRelationsByName('../timeline-item/index') if (elements.length > 0) { const lastIndex = elements.length - 1 const { pending, position } = this.data elements.forEach((element, index) => { const isLast = pending ? index === Math.max(0, lastIndex - 1) : index === lastIndex const isPending = pending && index === lastIndex element.updateIsLastElement({ index, isLast, isPending, pending, position, }) }) } }, }, })