When a Vue page is loaded, I make an Ajax call in the mounted() event to retrieve data. In order to reconstruct the existing Pager object with all its required parameters, I create a new Pager instance each time.
If I don't do this, vm.Pager remains just an Object without necessary methods, causing it to fail the prop type check that is passed to it.
axios.post("/Home/GetList", vm.Pager)
.then(function (result)
{
var p = result.data.Pager;
vm.Pager = new Pager(p.PageSize, p.CurrentRecord, p.TotalCount);
//more operations on Pager fields
vm.ItemList = result.data.ListItems;
})
.catch(function (error)
{
alert(error);
});
In knockoutjs, there was a useful mapping function where you could specify the types to map without re-creating the object. This was especially handy for complex or nested Ajax data.
Is there a more efficient way to achieve this in Vue (or javascript) so that the type mapping from Ajax data can be done without the need to reconstruct the object?