PXD
v0.2.1-dev

Loading Bar

Display the progress of a page or action.

Default

<script setup>
import { useLoadingBar } from 'pxd'

function start() {
  useLoadingBar.start()
}

function error() {
  useLoadingBar.error()
}

function finish() {
  useLoadingBar.finish()
}
</script>

<template>
  <PStack>
    <PLoadingBar></PLoadingBar>

    <PButton @click="start">Start</PButton>
    <PButton @click="error">Error</PButton>
    <PButton @click="finish">Finish</PButton>
  </PStack>
</template>

Use loading bar locally

You can set mount target of loading by to prop.

<script setup>
import { ref, onMounted, nextTick } from 'vue'
import { useLoadingBar } from 'pxd'

const isRender = ref(false)

function start() {
  useLoadingBar.start('locally')
}

function finish() {
  useLoadingBar.finish('locally')
}

onMounted(() => {
  nextTick(() => {
    isRender.value = true
  })
})
</script>

<template>
  <PStack id="container" class="relative">
    <PLoadingBar v-if="isRender" to="#container" group="locally" class="-mt-6"></PLoadingBar>

    <PButton @click="start">Start</PButton>
    <PButton @click="finish">Finish</PButton>
  </PStack>
</template>

Manually

Like <Message/>, there can be multiple <LoadingBar/> components, but there may be different parameter configurations between different instances, and you can distinguish them by setting group

<script setup>
import { useLoadingBar } from 'pxd'

function start() {
  useLoadingBar.start('manually')
}

function finish() {
  useLoadingBar.finish('manually')
}

function increase() {
  useLoadingBar.increase('manually', 0.1)
}
</script>

<template>
  <PStack>
    <PLoadingBar group="manually" :trickle="false"></PLoadingBar>

    <PButton @click="start">Start</PButton>
    <PButton @click="increase">Increase</PButton>
    <PButton @click="finish">Finish</PButton>
  </PStack>
</template>

Props

NameTypeDefaultDescription
tostring | objectbodyTeleport target selector or element, switches the bar to absolute
groupstringdefaultListens only to useLoadingBar calls with the same group
minimumnumber0.08Progress ratio the bar starts from, 0.08 means 8%
tricklebooleantrueAuto-increase progress with a shrinking step, capped at 99.4%
hide-delaynumber500Delay in ms before hiding after finish or error
trickle-thresholdnumber300Minimum ms between two automatic progress steps

Source

Source