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
| Name | Type | Default | Description |
|---|---|---|---|
| to | string | object | body | Teleport target selector or element, switches the bar to absolute |
| group | string | default | Listens only to useLoadingBar calls with the same group |
| minimum | number | 0.08 | Progress ratio the bar starts from, 0.08 means 8% |
| trickle | boolean | true | Auto-increase progress with a shrinking step, capped at 99.4% |
| hide-delay | number | 500 | Delay in ms before hiding after finish or error |
| trickle-threshold | number | 300 | Minimum ms between two automatic progress steps |