[vue.js/Nuxt.js]GET/POST

create project & run

npx create-nuxt-app api_test

cd api_test
npm run dev

install axios

npm install --save axios

index.vue

<template>
  <div class="container">
    <div>
      <!-- <logo /> -->
      <div class="title">
        {{ title }}
      </div>
      <div class="subtitle">
        {{ msg }}
      </div>
      <p class="html_data">
        {{html_data}}
      </p>
    </div>
  </div>
</template>

<script>

const axios = require('axios');
let url = "/README.md";

export default {
  data: function(){
    return {
      title:'AXIOS',
      msg: 'GET SAMPLE'
    };
  },
  asyncData: async function(){
    let ret = await axios.get(url);
    return { html_data: ret.data };
  }
}
</script>

<style>
.container {
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.title {
  font-family: 'Quicksand', 'Source Sans Pro', -apple-system, BlinkMacSystemFont,
    'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  display: block;
  font-weight: 300;
  font-size: 20px;
  color: #35495e;
  letter-spacing: 1px;
  padding-bottom: 5px;
}

.subtitle {
  font-weight: 300;
  font-size: 14px;
  color: #526488;
  word-spacing: 5px;
  padding-bottom: 15px;
}

.links {
  padding-top: 15px;
}
</style>

 

※staticフォルダは /README.mdのようにアクセスできる

 

Leave a Reply