Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
<template>
<div class="home">
<img alt="Vue with Spring logo" src="../assets/spring-boot-vuejs-logo.png">
<HelloSpringWorld hellomsg="Welcome to your Vue.js (+ TypeScript) powered Spring Boot App"/>
<HelloSpringWorld :hellomsg="hellomsg"/>
<div class="refresh-section">
<button class="btn btn-primary" @click="refreshData" :disabled="loading">
{{ loading ? '加载中...' : '刷新数据' }}
</button>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import HelloSpringWorld from '@/components/HelloSpringWorld.vue'; // @ is an alias to /src
import api from '@/api/backend-api';

export default defineComponent({
name: 'Home',
components: {
HelloSpringWorld,
},
data() {
return {
hellomsg: 'Welcome to your Vue.js (+ TypeScript) powered Spring Boot App',
loading: false
};
},
mounted() {
this.refreshData();
},
methods: {
async refreshData() {
if (this.loading) return;

this.loading = true;
try {
const response = await api.hello();
this.hellomsg = response.data;
} catch (error) {
console.error('Failed to refresh data:', error);
this.hellomsg = '获取数据失败,请稍后重试';
} finally {
this.loading = false;
}
}
}
});
</script>

<style scoped>
.refresh-section {
margin-top: 20px;
}
</style>