Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
src/vant-weapp/tabbar-item/index.js
@@ -1,23 +1,31 @@
import { VantComponent } from '../common/component';
import { useParent } from '../common/relation';
VantComponent({
  props: {
    info: null,
    name: null,
    icon: String,
    dot: Boolean,
    iconPrefix: {
      type: String,
      value: 'van-icon',
    },
  },
  relation: {
    name: 'tabbar',
    type: 'ancestor',
    current: 'tabbar-item',
  },
  relation: useParent('tabbar'),
  data: {
    active: false,
    activeColor: '',
    inactiveColor: '',
  },
  methods: {
    onClick() {
      if (this.parent) {
        this.parent.onChange(this);
      const { parent } = this;
      if (parent) {
        const index = parent.children.indexOf(this);
        const active = this.data.name || index;
        if (active !== this.data.active) {
          parent.$emit('change', active);
        }
      }
      this.$emit('click');
    },
@@ -40,9 +48,9 @@
      if (parentData.inactiveColor !== data.inactiveColor) {
        patch.inactiveColor = parentData.inactiveColor;
      }
      return Object.keys(patch).length > 0
        ? this.set(patch)
        : Promise.resolve();
      if (Object.keys(patch).length > 0) {
        this.setData(patch);
      }
    },
  },
});