Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- 'use strict';
- ACMESTORE.homeslider.homePageProducts = function(){
- var app = new Vue({
- el:'#root',
- data:{
- featured:[],
- products:[],
- count:0,
- loading:false
- },
- //método para pegar os dados do backend(php)
- methods:{
- getFeaturedProducts: function () {
- this.loading = true;
- //fazer mais de uma requisição ao mesmo tempo
- axios.all(
- [
- axios.get('/ecommerce/public/featured'), axios.get('/ecommerce/public/get-products')
- ]
- ).then(axios.spread(function(featuredResponse, productsResponse){
- app.featured = featuredResponse.data.featured;
- app.products = productsResponse.data.products;
- app.count = productsResponse.data.count;
- app.loading = false;
- }));
- },
- stringLimit: function(string, value){
- return ACMESTORE.module.truncateString(string, value);
- },
- addToCart:function(id){
- ACMESTORE.module.addItemToCart(id, function(message){
- $('.notify').slideDown(400).delay(4000).slideUp(300).html(message);
- });
- },
- loadMoreProducts: function(){
- var token = $('.display-products').data('token');
- this.loading = true;
- var data = $.param({next: 4, token: token, count: app.count});
- axios.post('/ecommerce/public/load-more', data).then(function(response){
- app.products = response.data.products;
- app.count = response.data.count;
- app.loading = false;
- });
- }
- },
- created: function(){
- this.getFeaturedProducts();
- },
- mounted: function(){
- $(window).scroll(function(){
- if($(window).scrollTop() + $(window).height() == $(document).height()){
- app.loadMoreProducts();
- }
- });
- }
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement