index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <PageWrapper title="动画组件示例">
  3. <div class="flex">
  4. <Select
  5. :options="options"
  6. v-model:value="value"
  7. placeholder="选择动画"
  8. :style="{ width: '150px' }"
  9. />
  10. <a-button type="primary" class="ml-4" @click="start"> start </a-button>
  11. </div>
  12. <component :is="`${value}Transition`">
  13. <div class="box" v-show="show"></div>
  14. </component>
  15. </PageWrapper>
  16. </template>
  17. <script lang="ts">
  18. import { defineComponent, ref } from 'vue';
  19. import { Select } from 'ant-design-vue';
  20. import { PageWrapper } from '/@/components/Page';
  21. import {
  22. FadeTransition,
  23. ScaleTransition,
  24. SlideYTransition,
  25. ScrollYTransition,
  26. SlideYReverseTransition,
  27. ScrollYReverseTransition,
  28. SlideXTransition,
  29. ScrollXTransition,
  30. SlideXReverseTransition,
  31. ScrollXReverseTransition,
  32. ScaleRotateTransition,
  33. ExpandXTransition,
  34. ExpandTransition,
  35. } from '/@/components/Transition';
  36. const transitionList = [
  37. 'Fade',
  38. 'Scale',
  39. 'SlideY',
  40. 'ScrollY',
  41. 'SlideYReverse',
  42. 'ScrollYReverse',
  43. 'SlideX',
  44. 'ScrollX',
  45. 'SlideXReverse',
  46. 'ScrollXReverse',
  47. 'ScaleRotate',
  48. 'ExpandX',
  49. 'Expand',
  50. ];
  51. const options = transitionList.map((item) => ({
  52. label: item,
  53. value: item,
  54. key: item,
  55. }));
  56. export default defineComponent({
  57. components: {
  58. Select,
  59. PageWrapper,
  60. FadeTransition,
  61. ScaleTransition,
  62. SlideYTransition,
  63. ScrollYTransition,
  64. SlideYReverseTransition,
  65. ScrollYReverseTransition,
  66. SlideXTransition,
  67. ScrollXTransition,
  68. SlideXReverseTransition,
  69. ScrollXReverseTransition,
  70. ScaleRotateTransition,
  71. ExpandXTransition,
  72. ExpandTransition,
  73. },
  74. setup() {
  75. const value = ref('Fade');
  76. const show = ref(true);
  77. function start() {
  78. show.value = false;
  79. setTimeout(() => {
  80. show.value = true;
  81. }, 300);
  82. }
  83. return { options, value, start, show };
  84. },
  85. });
  86. </script>
  87. <style lang="less" scoped>
  88. .box {
  89. width: 150px;
  90. height: 150px;
  91. margin-top: 20px;
  92. background-color: rgb(126, 170, 236);
  93. }
  94. </style>