1

I am trying to fetch data from the server using Vue + Vuex + Vue resource.On button click I want to hit Http request and show in list format .I tried like that.Here is my code

https://plnkr.co/edit/EAaEekLtoiGPvxkmAtrt?p=preview

// Code goes here

var store = new Vuex.Store({
    state: {
        Item: []
    },
    mutations: {
        getItems: function (state) {

        }

    },
    actions: {
        fetchData:function (context) {
            this.$http.get('/data.json', function(v1users)
                {
                   // this.$set('v1_user',v1users);
            });
        }
    }
})

var httprequest = Vue.extend({
    "template": '#http_template',
    data: function () {
        return {
            items: store.state.Item
        }
    },
    methods: {
        fetchData: function () {
          store.dispatch('fetchData')
        },

    }
})

Vue.component('httprequest', httprequest);

var app = new Vue({
    el: '#App',
    data: {},


})

; any udpdate?

1 Answer 1

1

Try using Vue.http.get instead of this.$http.get.

Vuex doesn't have access to $http directly from instance.

Sign up to request clarification or add additional context in comments.

5 Comments

could you please share plunker
how I will do that ?
No need for plunker.. Just please replace this.$http.get with Vue.http.get in your code. That's the only change you need to do.
I am able to fetch data .but how I will pass this data to component
You need to return promise in vues action. Here's some more details on how to to just that: stackoverflow.com/questions/40165766/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.