<template> <div id="app" class="container"> <h1 class="title">Frontend App</h1> <p class="subtitle">Click the button below to get a message from the backend service.</p> <button @click="fetchMessage" class="action-button"> Get Message from Backend </button> <p v-if="message" class="message-display"> <strong>{{ message }}</strong> </p> </div> </template>
<script> import axios from 'axios';
export default { name: 'App', data() { return { message: '' }; }, methods: { fetchMessage() { // Show a loading message immediately this.message = 'Loading...'; axios.get('/api/hello') .then(response => { this.message = response.data.message; }) .catch(error => { console.error("There was an error!", error); this.message = 'Failed to load message from backend.'; }); } } } </script>
<style> /* Import a nice font from Google Fonts (optional but recommended) */ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
/* Basic styles for the whole page */ body { background-color: #f4f7f6; font-family: 'Inter', sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; }