index.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. },
  34. data: {
  35. active: false
  36. },
  37. methods: {
  38. onClick() {
  39. if (this.parent) {
  40. this.parent.onChange(this);
  41. }
  42. this.$emit('click');
  43. },
  44. updateFromParent() {
  45. const { parent } = this;
  46. if (!parent) {
  47. return;
  48. }
  49. const index = parent.children.indexOf(this);
  50. const parentData = parent.data;
  51. const { data } = this;
  52. const active = (data.name || index) === parentData.active;
  53. const patch = {};
  54. if (active !== data.active) {
  55. patch.active = active;
  56. }
  57. if (parentData.activeColor !== data.activeColor) {
  58. patch.activeColor = parentData.activeColor;
  59. }
  60. if (parentData.inactiveColor !== data.inactiveColor) {
  61. patch.inactiveColor = parentData.inactiveColor;
  62. }
  63. return Object.keys(patch).length > 0
  64. ? this.set(patch)
  65. : Promise.resolve();
  66. }
  67. }
  68. });
  69. export default global['__wxComponents']['vant/tabbar-item/index']
  70. </script>
  71. <style platform="mp-weixin">
  72. @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}
  73. </style>