TomonoriSoejima / Tejun

notes related to working cases
5 stars 3 forks source link

How to test RUM stuff #160

Open TomonoriSoejima opened 5 months ago

TomonoriSoejima commented 5 months ago

Creating a sample single-page application (SPA) with Vue.js involves several key steps. For simplicity, I'll outline a basic example: a task manager app where you can add and list tasks. This example assumes you have basic knowledge of HTML, CSS, and JavaScript, and that you have Node.js and Vue CLI installed.

1. Project Setup

First, create a new Vue project using Vue CLI:

vue create task-manager-app

Choose the default setup. Once the project is created, navigate to the project directory:

cd task-manager-app

2. Modifying App.vue

Open the src/App.vue file. This is the main component of your Vue app. Modify it to include a simple task manager layout:

<template>
  <div id="app">
    <h1>Task Manager</h1>
    <div>
      <input v-model="newTask" @keyup.enter="addTask" placeholder="Add a new task">
      <button @click="addTask">Add</button>
    </div>
    <ul>
      <li v-for="task in tasks" :key="task.id">
        {{ task.title }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      newTask: '',
      tasks: []
    };
  },
  methods: {
    addTask() {
      if (this.newTask.trim() === '') return;
      this.tasks.push({ id: Date.now(), title: this.newTask });
      this.newTask = '';
    }
  }
};
</script>

<style>
/* Add your styles here */
</style>

3. Running the App

To run your Vue app, use the following command in your project directory:

npm run serve

This will start a development server. Open your browser and navigate to the URL provided in the terminal (usually http://localhost:8080/).

4. Adding Vue Router (Optional)

For a more advanced SPA, you might want to add different pages/routes using Vue Router.

First, install Vue Router:

npm install vue-router

Then, create a router.js file in the src directory:

import Vue from 'vue';
import Router from 'vue-router';
import Home from './components/Home.vue';

Vue.use(Router);

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    }
  ]
});

Create a Home.vue component inside src/components. This will be your homepage.

Update main.js to use the router:

import Vue from 'vue';
import App from './App.vue';
import router from './router';

Vue.config.productionTip = false;

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');

Now, your SPA has routing capabilities.

5. Enhancing Your SPA

You can enhance your SPA by:

Remember, this is a basic example to get you started. Vue.js is very flexible and allows for much more complex applications.

TomonoriSoejima commented 5 months ago

https://chat.openai.com/share/9adeea32-05e5-452e-bea0-566ebedb0696