Blame view

src/ui/vant-weapp/tabbar/index.js 1.66 KB
simon committed
1 2 3 4 5 6 7
import { VantComponent } from '../common/component';
VantComponent({
    relation: {
        name: 'tabbar-item',
        type: 'descendant',
        linked(target) {
            this.children.push(target);
simon committed
8 9
            target.parent = this;
            target.updateFromParent();
simon committed
10 11
        },
        unlinked(target) {
simon committed
12 13
            this.children = this.children.filter((item) => item !== target);
            this.updateChildren();
simon committed
14 15 16
        }
    },
    props: {
simon committed
17 18 19 20 21 22 23 24 25 26 27 28
        active: {
            type: null,
            observer: 'updateChildren'
        },
        activeColor: {
            type: String,
            observer: 'updateChildren'
        },
        inactiveColor: {
            type: String,
            observer: 'updateChildren'
        },
simon committed
29 30 31 32
        fixed: {
            type: Boolean,
            value: true
        },
simon committed
33 34 35 36
        border: {
            type: Boolean,
            value: true
        },
simon committed
37 38 39
        zIndex: {
            type: Number,
            value: 1
simon committed
40 41 42 43
        },
        safeAreaInsetBottom: {
            type: Boolean,
            value: true
simon committed
44 45
        }
    },
simon committed
46 47
    beforeCreate() {
        this.children = [];
simon committed
48 49
    },
    methods: {
simon committed
50 51 52
        updateChildren() {
            const { children } = this;
            if (!Array.isArray(children) || !children.length) {
simon committed
53 54
                return Promise.resolve();
            }
simon committed
55
            return Promise.all(children.map((child) => child.updateFromParent()));
simon committed
56 57
        },
        onChange(child) {
simon committed
58 59 60 61
            const index = this.children.indexOf(child);
            const active = child.data.name || index;
            if (active !== this.data.active) {
                this.$emit('change', active);
simon committed
62 63 64 65
            }
        }
    }
});