[Vuejs]-How to assign ajax response to data element with vuejs

2👍

You lost your context when you defined your ajax callback.

$.ajax({
  url: '/things.json',
  success: function(res) {
    this.things = res;
  }.bind(this)
})

Example.

You could also do it with some of the code you commented out.

mounted: function() {
  const that = this
  $.ajax({
    url: '/things.json',
    success: function(res) {
      that.things = res;
    }
  });
}
👤Bert

Leave a comment