index.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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]" />
  6. </GateContent>
  7. </Gate>
  8. <template v-if="showCtrl">
  9. <span v-if="index !== 0" class="left" @click="prevHandler"><UIIcon type="left" /></span>
  10. <span v-if="index !== items.length - 1" class="right" @click="nextHandler"><UIIcon type="pull-more" /></span>
  11. </template>
  12. <slot name="attach" :active="items[index]" />
  13. </div>
  14. </template>
  15. <script lang="ts" setup>
  16. import { defineProps, ref, watchEffect } from 'vue'
  17. import UIIcon from '@kankan/components/basic/icon'
  18. import { Gate, GateContent } from '../gate'
  19. defineOptions({
  20. name: 'UISlide',
  21. })
  22. const props = defineProps({
  23. items: Array,
  24. currentIndex: {
  25. type: Number,
  26. default: 0,
  27. },
  28. showCtrl: {
  29. type: Boolean,
  30. },
  31. })
  32. const index = ref()
  33. watchEffect(() => (index.value = props.currentIndex))
  34. const prevHandler = () => {
  35. if (index.value > 0) {
  36. index.value--
  37. }
  38. }
  39. const nextHandler = () => {
  40. if (index.value < props.items.length - 1) {
  41. index.value++
  42. }
  43. }
  44. </script>
  45. <!-- <script>
  46. export default { name: 'UiSlide' }
  47. </script> -->