1

Tell me please, how in DATA to write data from the AJAX response? Example:

var example = new Vue({
    el: '#example',
    data:{
        myArr: []
    },
    created: function () {
        $.getJSON('data.json', function(data) {
            this.myArr = data;
        });
    }
  });

The problem is that in myArr, the response data is not written. How to solve this? Thank you.

1

1 Answer 1

3

Can you try this ? Basically this inside the ajax is not exactly the one you would expect.

var example = new Vue({
    el: '#example',
    data:{
        myArr: []
    },
    created: function () {
        var vm = this;
        $.getJSON('data.json', function(data) {
            vm.myArr = data;
        });
    }
  });

You can also use reactivity setting method $set instead of directly assigning to the vm.myArr : https://v2.vuejs.org/v2/guide/reactivity.html

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

1 Comment

Thank you for help

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.