LoginSignup
1
0

More than 3 years have passed since last update.

axiosをグローバルに呼び出す

Posted at

設定する

src/main.js
import Vue from 'vue';
import axios from 'axios';
.
.
.
Vue.prototype.$http = axios.create(
  { baseURL: process.env.VUE_APP_API_URI, withCredentials: true },
);

呼び出す

.
.
.
  methods: {
    fetchItemList() {
      return new Promise((resolve) => {
        this.$http.get('/api/v1/items').then((response) => {
          this.itemList = response.data.index;
          resolve();
        }).catch(省略);
      });
    },
  },
.
.
.

みたいな感じで this.$http で呼び出せます

おしまい

1
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
1
0