index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="nut-tabbar" :class="{ bottom }">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script lang="ts">
  7. import { provide, reactive, watch } from 'vue';
  8. import { createComponent } from '@/utils/create';
  9. const { create } = createComponent('tabbar');
  10. import tabbaritem from '@/packages/tabbaritem/index.vue';
  11. export default create({
  12. children: [tabbaritem],
  13. props: {
  14. show: {
  15. type: [Number, String],
  16. default: 0
  17. },
  18. bottom: {
  19. type: Boolean,
  20. default: false
  21. },
  22. type: {
  23. type: String,
  24. default: 'base'
  25. },
  26. size: {
  27. type: String,
  28. default: '20px'
  29. },
  30. unactiveColor: {
  31. type: String,
  32. default: '#000000'
  33. },
  34. activeColor: {
  35. type: String,
  36. default: '#fa2c19'
  37. }
  38. },
  39. emits: ['tab-switch', 'update:show'],
  40. setup(props, { emit, slots }) {
  41. const mdValue = reactive({
  42. val: props.show,
  43. children: []
  44. });
  45. function changeIndex(active: number) {
  46. emit('update:show', active);
  47. parentData.modelValue = active;
  48. emit('tab-switch', parentData.children[active], active);
  49. }
  50. let parentData = reactive({
  51. children: mdValue.children,
  52. size: props.size,
  53. modelValue: mdValue.val,
  54. unactiveColor: props.unactiveColor,
  55. activeColor: props.activeColor,
  56. changeIndex
  57. });
  58. provide('parent', parentData);
  59. watch(
  60. () => props.show,
  61. value => {
  62. parentData.modelValue = value;
  63. }
  64. );
  65. return {
  66. changeIndex
  67. };
  68. }
  69. });
  70. </script>
  71. <style lang="scss">
  72. @import 'index.scss';
  73. </style>