🦔

Vueでaxiosを使う

2021/06/23に公開

main.js

import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)

Example.vue

<template>
    <div>
        {{ products }}
    </div>
</template>

<script>
export default {
    name: 'Test',
    data () {
        return {
	    products: []
	}
    },
    created () {
        this.getProducts()
    },
    methods: {
        getProducts () {
	    this.axios.get('http://localhost:5000/products')
	    .then(response => {
	        this.products = response.data
	    })
	}
    }
}
</script>

Discussion