index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="ui-slide">
  3. <Gate :index="index">
  4. <GateContent v-for="(item, i) in items" :key="i">
  5. <slot :raw="item" :active="items[index]"></slot>
  6. </GateContent>
  7. </Gate>
  8. <template v-if="showCtrl">
  9. <span class="left" @click="prevHandler" v-if="index !== 0"><UIIcon type="left" /></span>
  10. <span class="right" @click="nextHandler" v-if="index !== items.length - 1"><UIIcon type="pull-more" /></span>
  11. </template>
  12. <slot name="attach" :active="items[index]"></slot>
  13. </div>
  14. </template>
  15. <script setup>
  16. import { Gate, GateContent } from '../gate'
  17. import { defineProps, ref, watchEffect } from 'vue'
  18. import UIIcon from '../icon'
  19. const props = defineProps({
  20. items: Array,
  21. currentIndex: {
  22. type: Number,
  23. default: 0,
  24. },
  25. showCtrl: {
  26. type: Boolean,
  27. },
  28. })
  29. const index = ref()
  30. watchEffect(() => (index.value = props.currentIndex))
  31. const prevHandler = () => {
  32. if (index.value > 0) {
  33. index.value--
  34. }
  35. }
  36. const nextHandler = () => {
  37. if (index.value < props.items.length - 1) {
  38. index.value++
  39. }
  40. }
  41. </script>
  42. <script>
  43. export default { name: 'UiSlide' }
  44. </script>