Skip to content

Commit 39c6734

Browse files
committed
docs(demo): Add loading indicator to new todo submission
1 parent c7f22df commit 39c6734

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

examples/vue-todo-app/src/components/TodoList.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
@keyup.enter="handleAdd"
1818
placeholder="What needs to be done?"
1919
class="todo-input"
20+
:disabled="isLoading"
2021
/>
21-
<button @click="handleAdd" class="add-btn">Add</button>
22+
<button @click="handleAdd" class="add-btn" :disabled="isLoading">{{isLoading ? ' ... ' : 'Add'}}</button>
2223
</div>
2324

2425
<Suspense>
@@ -35,7 +36,7 @@
3536
<script setup lang="ts">
3637
import { ref, computed } from 'vue';
3738
import { useRoute } from 'vue-router';
38-
import { useController } from '@data-client/vue';
39+
import { useController, useLoading } from '@data-client/vue';
3940
import { TodoResource } from '../resources/TodoResource';
4041
import TodoListContent from './TodoListContent.vue';
4142
import UserHeader from './UserHeader.vue';
@@ -46,7 +47,7 @@ const newTodoTitle = ref('');
4647
4748
const userId = computed(() => Number(route.params.userId));
4849
49-
const handleAdd = async () => {
50+
const [handleAdd, isLoading] = useLoading(async () => {
5051
if (!newTodoTitle.value.trim()) return;
5152
5253
await ctrl.fetch(TodoResource.getList.unshift, { userId: userId.value }, {
@@ -56,7 +57,7 @@ const handleAdd = async () => {
5657
});
5758
5859
newTodoTitle.value = '';
59-
};
60+
});
6061
</script>
6162

6263
<style scoped>

examples/vue-todo-app/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"noUnusedParameters": true,
2121
"noFallthroughCasesInSwitch": true
2222
},
23-
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
23+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "env.d.ts"],
2424
"references": [{ "path": "./tsconfig.node.json" }]
2525
}
2626

0 commit comments

Comments
 (0)