🦔

Vueでaxiosを使う

1 min read

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

ログインするとコメントできます