wd-backtop.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <wd-transition :show="show" name="fade">
  3. <view
  4. :class="`wd-backtop ${customClass} is-${shape}`"
  5. :style="`z-index: ${zIndex}; bottom: ${bottom}px; right: ${right}px; ${customStyle}`"
  6. @click="handleBacktop"
  7. >
  8. <slot v-if="$slots.default"></slot>
  9. <wd-icon v-else custom-class="wd-backtop__backicon" name="backtop" :custom-style="iconStyle" />
  10. </view>
  11. </wd-transition>
  12. </template>
  13. <script lang="ts">
  14. export default {
  15. name: 'wd-backtop',
  16. options: {
  17. addGlobalClass: true,
  18. virtualHost: true,
  19. styleIsolation: 'shared'
  20. }
  21. }
  22. </script>
  23. <script lang="ts" setup>
  24. import wdTransition from '../wd-transition/wd-transition.vue'
  25. import wdIcon from '../wd-icon/wd-icon.vue'
  26. import { computed } from 'vue'
  27. import { backtopProps } from './types'
  28. const props = defineProps(backtopProps)
  29. const show = computed(() => props.scrollTop > props.top)
  30. function handleBacktop() {
  31. uni.pageScrollTo({
  32. scrollTop: 0,
  33. duration: props.duration
  34. })
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. @import './index.scss';
  39. </style>