custom-tab-pane.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="tab-pane">
  3. <template v-if="show">
  4. <slot></slot>
  5. </template>
  6. <template v-else>
  7. <view style="width: 750rpx;height: 0;"></view>
  8. </template>
  9. </view>
  10. </template>
  11. <script setup>
  12. // // #ifdef VUE3
  13. // import { ref, watch } from 'vue';
  14. // const data_props = defineProps({
  15. // label: [String, Number],
  16. // name: [String, Number]
  17. // });
  18. // const show = ref(false);
  19. // let timer = 0;
  20. // const watchTabKey = `watchTabValue_${data_props.name.split('_')[0]}`;
  21. // console.log(watchTabKey)
  22. // watch(() => data_props.label, (newValue, oldValue) => {
  23. // uni.$emit(watchTabKey, { newValue: newValue, oldValue: oldValue, name: data_props.name });
  24. // }, { immediate: true });
  25. // uni.$on('putChange', item => {
  26. // if (timer) clearTimeout(timer);
  27. // show.value = true;
  28. // timer = setTimeout(() => {
  29. // show.value = data_props.name == item.name;
  30. // }, item.duration)
  31. // })
  32. // // #endif
  33. </script>
  34. <script>
  35. export default {
  36. props: ['label', 'name'],
  37. data() {
  38. return {
  39. timer: 0,
  40. show: false,
  41. watchTabKey: `watchTabValue_${this.name.split('_')[0]}`,
  42. putChangeKey: `putChange_${this.name.split('_')[0]}`
  43. }
  44. },
  45. created() {
  46. uni.$on(this.putChangeKey, item => {
  47. if (this.timer) clearTimeout(this.timer);
  48. this.show = true;
  49. this.timer = setTimeout(() => {
  50. this.show = this.name == item.name;
  51. }, item.duration)
  52. })
  53. },
  54. watch: {
  55. label: {
  56. deep: true,
  57. handler(newValue, oldValue) {
  58. uni.$emit(this.watchTabKey, { newValue: newValue, oldValue: oldValue, name: this.name });
  59. },
  60. immediate: true
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .tab-pane {
  67. width: 750rpx;
  68. // #ifndef APP-PLUS-NVUE
  69. flex-shrink: 0;
  70. // #endif
  71. }
  72. </style>