Skip to content

Instantly share code, notes, and snippets.

<template>
<Promised :promise="usersPromise">
<template v-slot:pending>
<p>Loading...</p>
</template>
<template v-slot="data">
<ul>
<li v-for="user in data">{{ user.name }}</li>
</ul>
</template>
<template>
<div v-if="error"> {{ error.message }}</div>
<Suspense v-else>
<template #default>
<Admins />
<Users />
</template>
<template #fallback>
<div>Loading...</div>
</template>
<div v-for="user in users"> {{ user.name }} </div>
export default defineComponent({
async setup() {
const users = await fetchUsers();
return { users };
}
});
<template>
<div>
<div v-if="isLoading"> Loading ... </div>
<div v-else="error"> {{ error.message }} <button @click="getUsers">try again</button> </div>
<div v-else> {{ data }} </div>
</div>
</template>
import { ref } from 'vue';
export default defineComponent({
setup() {
const isLoading = ref(false);
const error = ref(null);
const data = ref(null);
const getUsers = async () => {
isLoading.value = true;
try {
@MartinMalinda
MartinMalinda / takprefetch.ts
Last active June 12, 2020 10:20
useTaskPrefetch
export function reviveTaskInstance(instance: TaskInstance<any>) {
if (instance.isError) {
instance._deferredObject.promise = Promise.reject(instance.error);
} else {
// TODO: fix this
instance._deferredObject.promise = Promise.resolve(instance.value) as unknown as Promise<void>;
}
instance.cancel = () => {};
instance.canceledOn = (signal) => instance;
[
{
"id": "AD",
"name": "Andorra",
"type": "land",
"items": []
},
{
"id": "AE",
"name": "United Arab Emirates",
[
{
"id": "AD",
"name": "Andorra",
"type": "land",
"items": [
{
"fieldId": 0,
"value": 0
},
@MartinMalinda
MartinMalinda / map-data.json
Last active October 29, 2019 17:58
Countries by the number of road motor vehicles per 1,000 inhabitants Source: https://en.wikipedia.org/wiki/List_of_countries_by_vehicles_per_capita
[
{
"id": "SM",
"name": "San Marino",
"type": "land",
"items": [
{
"fieldId": 0,
"value": 1263
}