Vue通过axios请求数据

时间:2020-05-01

安装插件

npm install axios --save

<template></template>

<script>
    import Son1 from './components/Son1.vue'
    import Son2 from './components/Son2.vue'
    import axios from 'axios';

    export default {
        name: 'App',
        components: {
            Son1,
            Son2
        },
        mounted() {
            axios.get('https://www.wyzda.com')
                .then(response => {
                    console.log(response.data);
                })
                .catch(error => {
                    console.log(error);
                });
        },
        methods: {},
        data: function () {
            return {
                'msg': ''
            };
        }
    }
</script>

<style>

</style>