Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'get' of undefined"

请问我如下这样,为什么发生错误,store里调用不到this.$http的get方法吗?
//main.js

import store from './store'
import axios from 'axios'
import App from './App.vue'
Vue.prototype.$http = axios

//App.vue

created()?{
 this.$store.dispatch('allProducts')
 },

//store/index.js

actions: {
    allProducts()?{
        this.$http.get(`http://localhost:3000/login`).
        then(response => {console.log(response)}
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
491 views
Welcome To Ask or Share your Answers For Others

1 Answer

1、axios用法不对,要先实例化一个axios出来;
2、vuex中this指向的并不是vue实例。
看一下axios的文档吧axios


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...