[Vuejs]-Passing data to an array in Vue.js

0๐Ÿ‘

Try writing the method like this

 $.ajax({
        method: "GET",
        url: "/api/Article/GetUserArticles"
        success: function (data) {
            UserArticles  = data;
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    })
}

0๐Ÿ‘

I had to use an arrow function in my ajax code inside of the done function as well as add the this keyword. Note the difference:

getUserArticles: function () {
    $.ajax({
        method: "GET",
        url: "/api/Article/GetUserArticles"
    }).done((rData, status, jq) => {
        this.UserArticles = rData;
        toastr.success('', 'Retrieved User Articles');

    }).fail(function (rData, status, error) {
        var result = $.parseJSON(rData.responseText);
        toastr.warning(result.messages, 'Retrieve User Articles')
    });
}

Leave a comment