标签云

微信群

扫码加入我们

WeChat QR Code

In a Vue page, I have a call to get data using Ajax when the mounted() event is fired. The code recreates the existing Pager using a new Pager object where it has to pass in all the parameters in the constructor to reconstruct it. If I don't do this, vm.Pager is just an Object and does not have some needed methods, and fails the prop type check that it gets passed to. axios.post("/Home/GetList", vm.Pager).then(function (result){ var p = result.data.Pager; vm.Pager = new Pager(p.PageSize, p.CurrentRecord, p.TotalCount); // etc. (Pager has additional fields...) vm.ItemList = result.data.ListItems;}).catch(function (error){alert(error); });In the knockoutjs, there was a mapping function and you could what tell it what types to map without having to recreate the object. This was convenient, particularly for more complicated or nested Ajax data.Is there a better way to do this in Vue (or javascript) where it maps the type from the Ajax without having to recreate it?


What does the Pager constructor look like? Does it do any transformation of the data or does it just directly assign properties?

2019年03月27日16分22秒

It just is a simple assignment. The Pager example above is a simple one where it is fairly easy to create a constructor that works. What I am looking for is a strategy (plugin, technique, etc.) for more complex object graphs, ideally where you would not have to create custom constructors.

2019年03月26日16分22秒