0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vueのサンプル

Posted at

簡単なVueのサンプルになります。

公式ドキュメントにも似たようなシンプルなサンプルが沢山転がっています

App.vue
<template>
  <div class="container">
    <h1>{{ title }}</h1>
    <p>カウント: {{ count }}</p>
    <button @click="increment">カウントを増やす</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const title = 'Vue 3 カウンターサンプル'
const count = ref(0)

const increment = () => {
  count.value++
}
</script>

<style scoped>
.container {
  text-align: center;
  margin-top: 100px;
  font-family: Arial, sans-serif;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
</style>

データのリクエストサンプル

api.js
// api.js
import axios from 'axios';

// ベースURLを設定(.envなどで管理するのがベスト)
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://example.com/api';

// axiosインスタンスの作成
const apiClient = axios.create({
  baseURL: API_BASE_URL,
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json',
  },
});

// GETリクエストの例
export const fetchData = async (endpoint) => {
  try {
    const response = await apiClient.get(endpoint);
    return response.data;
  } catch (error) {
    console.error('API取得エラー:', error);
    throw error;
  }
};

// POSTリクエストの例
export const postData = async (endpoint, payload) => {
  try {
    const response = await apiClient.post(endpoint, payload);
    return response.data;
  } catch (error) {
    console.error('API送信エラー:', error);
    throw error;
  }
};
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?