axio.get(“http:xxx/”).then((res)=>{  処理  });

 

json_test_async.vue

<template>
  <div class="container">
    <div>
      <!-- <logo /> -->
      <div class="title">
        {{ title }}
      </div>
      <div class="subtitle">
        {{ msg }}
      </div>
      <button @click="get_json_click">get json</button>

      <p class="html_data">
        {{json_data}}
      </p>

      <table>
        <tr>
          <th>user id</th>
          <td>{{json_data.userId}}</td>
        </tr>
        <tr>
          <th>id</th>
          <td>{{json_data.id}}</td>
        </tr>
        <tr>
          <th>title</th>
          <td>{{json_data.title}}</td>
        </tr>
        <tr>
          <th>body</th>
          <td>{{json_data.body}}</td>
        </tr>        
      </table>

    </div>
  </div>
</template>

<script>
const axios = require('axios');
let url = "https://jsonplaceholder.typicode.com/posts/1";

export default {
  data: function(){
    return {
      title:'AXIOS',
      msg: 'GET JSON',
      json_data: {},
    };
  },
  methods:{
    get_json_click: function(event){
      axios.get(url)
      .then( (ret)=>{
        this.json_data = ret.data;
      })
      .catch((error)=>{
        this.msg = 'ERROR';
      });
    }
  }
}
</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>

 

 

 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です