小编Rus*_*ion的帖子

“TypeError:无法读取未定义的属性‘get’”,Axios,Vue.JS

当尝试使用 axios 从 api 访问 get 请求时,我从 Vue 收到这个奇怪的错误,我收到“TypeError: Cannot read property 'get' of undefined”

在此输入图像描述

 <template>
    <div class="home">
        <h1>{{ msg }}</h1>
        <p>Welcome to your new single-page application, built with <a href="https://vuejs.org" target="_blank">Vue.js</a>.</p>
    </div>
</template>

<script>
    var Vue = require('vue');

   // import axios from "axios";

    window.axios=require('axios');
    export default {
        name: 'Home',
        props: {
            msg: String
        },
        component: {
        },   
        mounted: function () {
            alert('Hi ');
            this.axios.get('https://api.github.com/users')
                .then(value => {
                    alert(value);
                         
                });
        }

    };
</script>

<!-- Add "scoped" attribute to limit CSS …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component axios vuex vuejs2

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×1

vue-component ×1

vue.js ×1

vuejs2 ×1

vuex ×1