vuux
Version:
Vue3 Nuxt3 Nuxt4 组件库
32 lines (31 loc) • 783 B
JavaScript
import { ref as s, computed as u } from "vue";
import { Utils as i } from "@vuux/utils";
const w = () => {
const e = s(0), t = s(!1), r = s(!1);
let a = null;
const l = u(() => ({
width: e.value + "%"
})), o = () => {
const n = () => {
t.value && e.value < 90 && (e.value += 0.5, a = requestAnimationFrame(n));
};
a = requestAnimationFrame(n);
};
return {
visible: t,
isError: r,
style: l,
start: () => {
t.value = !0, r.value = !1, e.value = 0, a && (cancelAnimationFrame(a), a = null), o();
},
finish: async () => {
e.value = 100, await i.wait(300), t.value = !1;
},
error: async () => {
r.value = !0, e.value = 100, await i.wait(500), t.value = !1;
}
};
};
export {
w as useLoadingBar
};