UNPKG

@cran/vue.use

Version:

Cranberry Vue Use Utilities

15 lines (14 loc) 415 B
import { ref } from "@vue/runtime-dom"; export function usePromise(promise) { const state = ref("PENDING"); const result = ref(); const error = ref(); promise.then(function onThen(value) { result.value = value; state.value = "RESOLVED"; }, function onCatch(reason) { error.value = reason; state.value = "REJECTED"; }); return { result, state, error, }; }