Skip to content

Instantly share code, notes, and snippets.

@bachhm-dev
Created September 1, 2020 15:53
Show Gist options
  • Save bachhm-dev/056f6bbf1ffa8abb1ea329df22323fcf to your computer and use it in GitHub Desktop.
Save bachhm-dev/056f6bbf1ffa8abb1ea329df22323fcf to your computer and use it in GitHub Desktop.
import { ref } from "@vue/composition-api";
export default function(fn) {
const result = ref(null);
const loading = ref(false);
const error = ref(null);
const createPromise = async (...args) => {
loading.value = true;
try {
result.value = await fn(...args);
} catch (err) {
error.value = err;
} finally {
loading.value = false;
}
};
return { result, loading, error, createPromise };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment