Skip to content

Commit

Permalink
feat: add loading for request
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwong committed Jun 6, 2024
1 parent fbace37 commit 752d8b5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app": {
"title": "Opuntia",
"description": "Vite + Vue 3 starter template."
"description": "Vite + Vue 3 SPA starter template, it's fast."
},
"page": {
"home": {
Expand Down
2 changes: 1 addition & 1 deletion locales/zh.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app": {
"title": "Opuntia",
"description": "Vite + Vue 3 启动模板"
"description": "Vite + Vue 3 单页面应用启动模板,它很快"
},
"page": {
"home": {
Expand Down
13 changes: 13 additions & 0 deletions src/assets/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 17 additions & 4 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ const { t } = useI18n()
const todoList = ref<TodoList>([])
const emptyText = ref(t('empty'))
const loading = ref(false)
function fetchData() {
if (loading.value)
return
loading.value = true
getTodoListApi().then((res) => {
todoList.value = res.data
}).catch((err) => {
emptyText.value = err.message
}).finally(() => {
loading.value = false
})
}
</script>
Expand All @@ -29,16 +40,18 @@ function fetchData() {
{{ route.meta.title }}
</h1>
<div flex justify-center items-center my-5>
<TheButton lh-2 @click="fetchData">
<TheButton lh-4 @click="fetchData">
<img v-show="loading" mr-2 src="@/assets/loading.svg">
{{ t('page.home.get-todo-list') }}
</TheButton>
</div>
<ul v-for="item in todoList" :key="item.id" my-5 h-xl overflow-y-auto>
<li>
<ul v-if="todoList.length > 0" my-5 h-50 overflow-y-auto>
<li v-for="item in todoList" :key="item.id" text-base lh-normal>
<input type="checkbox" accent-primary>
{{ item.title }}
</li>
</ul>
<p v-if="todoList.length === 0" my-5 text-center op-75>
{{ t('empty') }}
{{ emptyText }}
</p>
</template>
10 changes: 4 additions & 6 deletions src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ body,
}

html {
background: theme('light-color');
color: theme('dark-color');
--at-apply: bg-neutral-100 text-neutral-900;
}

html.dark {
color-scheme: dark;
background: theme('dark-color');
color: theme('light-color');
--at-apply: bg-neutral-900 text-neutral-200;
}

a {
color: theme('primary-color');
--at-apply: color-primary;
}

#nprogress {
pointer-events: none;
}

#nprogress .bar {
background: theme('primary-color');
--at-apply: bg-primary;
opacity: 0.75;
position: fixed;
z-index: 1031;
Expand Down
6 changes: 3 additions & 3 deletions uno.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {

export default defineConfig({
theme: {
'light-color': '#f2f1ec',
'dark-color': '#171717',
'primary-color': '#15803d',
colors: {
primary: '#15803d',
},
},
shortcuts: [],
presets: [
Expand Down

0 comments on commit 752d8b5

Please sign in to comment.