Advertisement
Guest User

Untitled

a guest
May 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. (function(){
  2. 'use strict';
  3.  
  4. ACMESTORE.homeslider.homePageProducts = function(){
  5. var app = new Vue({
  6. el:'#root',
  7. data:{
  8. featured:[],
  9. products:[],
  10. count:0,
  11. loading:false
  12. },
  13. //método para pegar os dados do backend(php)
  14. methods:{
  15. getFeaturedProducts: function () {
  16. this.loading = true;
  17. //fazer mais de uma requisição ao mesmo tempo
  18. axios.all(
  19. [
  20. axios.get('/ecommerce/public/featured'), axios.get('/ecommerce/public/get-products')
  21. ]
  22. ).then(axios.spread(function(featuredResponse, productsResponse){
  23. app.featured = featuredResponse.data.featured;
  24. app.products = productsResponse.data.products;
  25. app.count = productsResponse.data.count;
  26. app.loading = false;
  27. }));
  28.  
  29. },
  30. stringLimit: function(string, value){
  31. return ACMESTORE.module.truncateString(string, value);
  32. },
  33. addToCart:function(id){
  34. ACMESTORE.module.addItemToCart(id, function(message){
  35. $('.notify').slideDown(400).delay(4000).slideUp(300).html(message);
  36. });
  37.  
  38. },
  39. loadMoreProducts: function(){
  40. var token = $('.display-products').data('token');
  41. this.loading = true;
  42.  
  43. var data = $.param({next: 4, token: token, count: app.count});
  44.  
  45. axios.post('/ecommerce/public/load-more', data).then(function(response){
  46. app.products = response.data.products;
  47. app.count = response.data.count;
  48. app.loading = false;
  49. });
  50. }
  51.  
  52. },
  53. created: function(){
  54. this.getFeaturedProducts();
  55. },
  56. mounted: function(){
  57. $(window).scroll(function(){
  58. if($(window).scrollTop() + $(window).height() == $(document).height()){
  59. app.loadMoreProducts();
  60. }
  61. });
  62. }
  63. });
  64. }
  65. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement