index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <uni-shadow-root class="vant-tabbar-item-index"><view :class="(utils.bem('tabbar-item', { active }))+' custom-class'" :style="'color: '+(active ? activeColor : inactiveColor)" @click="onClick">
  3. <view class="van-tabbar-item__icon">
  4. <van-icon v-if="icon" :name="icon" custom-class="van-tabbar-item__icon__inner"></van-icon>
  5. <block v-else>
  6. <slot v-if="active" name="icon-active"></slot>
  7. <slot v-else name="icon"></slot>
  8. </block>
  9. <van-info :dot="dot" :info="info" custom-class="van-tabbar-item__info"></van-info>
  10. </view>
  11. <view class="van-tabbar-item__text">
  12. <slot></slot>
  13. </view>
  14. </view></uni-shadow-root>
  15. </template>
  16. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  17. <script>
  18. import VanIcon from '../icon/index.vue'
  19. import VanInfo from '../info/index.vue'
  20. global['__wxVueOptions'] = {components:{'van-icon': VanIcon,'van-info': VanInfo}}
  21. global['__wxRoute'] = 'vant/tabbar-item/index'
  22. import { VantComponent } from '../common/component';
  23. VantComponent({
  24. props: {
  25. info: null,
  26. name: null,
  27. icon: String,
  28. dot: Boolean,
  29. },
  30. relation: {
  31. name: 'tabbar',
  32. type: 'ancestor',
  33. current: 'tabbar-item',
  34. },
  35. data: {
  36. active: false,
  37. },
  38. methods: {
  39. onClick() {
  40. if (this.parent) {
  41. this.parent.onChange(this);
  42. }
  43. this.$emit('click');
  44. },
  45. updateFromParent() {
  46. const { parent } = this;
  47. if (!parent) {
  48. return;
  49. }
  50. const index = parent.children.indexOf(this);
  51. const parentData = parent.data;
  52. const { data } = this;
  53. const active = (data.name || index) === parentData.active;
  54. const patch = {};
  55. if (active !== data.active) {
  56. patch.active = active;
  57. }
  58. if (parentData.activeColor !== data.activeColor) {
  59. patch.activeColor = parentData.activeColor;
  60. }
  61. if (parentData.inactiveColor !== data.inactiveColor) {
  62. patch.inactiveColor = parentData.inactiveColor;
  63. }
  64. return Object.keys(patch).length > 0
  65. ? this.set(patch)
  66. : Promise.resolve();
  67. },
  68. },
  69. });
  70. export default global['__wxComponents']['vant/tabbar-item/index']
  71. </script>
  72. <style platform="mp-weixin">
  73. @import '../common/index.css';.vant-tabbar-item-index{-webkit-flex:1;flex:1}.van-tabbar-item{display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;height:100%;color:#646566;color:var(--tabbar-item-text-color,#646566);font-size:12px;font-size:var(--tabbar-item-font-size,12px);line-height:1;line-height:var(--tabbar-item-line-height,1)}.van-tabbar-item__icon{position:relative;margin-bottom:5px;margin-bottom:var(--tabbar-item-margin-bottom,5px);font-size:18px;font-size:var(--tabbar-item-icon-size,18px)}.van-tabbar-item__icon__inner{display:block;min-width:1em}.van-tabbar-item--active{color:#1989fa;color:var(--tabbar-item-active-color,#1989fa)}.van-tabbar-item__info{margin-top:2px}
  74. </style>