toneee
251
5
Vue

Setting Variables

Posted 2 years ago by toneee

Hi All,

I have been following the Vue tutorials and am trying to get something really simple working, but seem to be missing something.

The process is getting some data via an API request, setting it to a variable and then displaying it in a html page.

Here is my code

new Vue({

    el: '#test',

    data: {
        tasks: []
    },

    mounted() {
        //axios.get('/api/tasks').then(response => console.log(response.data));
        axios.get('/api/tasks').then(response => this.tasks = response.data);
        console.log(this.tasks);
    }
});

The first commented out line works, it logs the data to the console, the problem arises when I try to set the tasks variable, it doesnt seem to get set. and the last line console.log shows an error as the variable isnt set.

Hope someone can help as I am sure its something simple I am missing.

Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.