最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How in livewire after clicking on gotoPage method to call JS function? - Stack Overflow

programmeradmin4浏览0评论

In laravel 7 with livewire 1.3 I have a listing with pagination and lazy images applied to any item image by calling JS function lazyImagesInit(lazyload 2.0.0-rc.2 is used) when page is loaded. But when I click on pagination link I lose lazy images effect for any new opened items images . Looking into the code of cach file I see that gotoPage method is used :

<?php if(is_array($element)): ?>
    <?php $__currentLoopData = $element; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page => $url): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if($page == $paginator->currentPage()): ?>
            <li class="page-item active d-none d-md-block" aria-current="page"><span class="page-link"><?php echo e($page); ?></span></li>
        <?php else: ?>
            <li class="page-item d-none d-md-block"><button type="button" class="page-link" wire:click="gotoPage(<?php echo e($page); ?>)"><?php echo e($page); ?></button></li>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>

If there is a way after calling of gotoPage to call my lazyImagesInit function?

Thanks!

In laravel 7 with livewire 1.3 I have a listing with pagination and lazy images applied to any item image by calling JS function lazyImagesInit(lazyload 2.0.0-rc.2 is used) when page is loaded. But when I click on pagination link I lose lazy images effect for any new opened items images . Looking into the code of cach file I see that gotoPage method is used :

<?php if(is_array($element)): ?>
    <?php $__currentLoopData = $element; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page => $url): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if($page == $paginator->currentPage()): ?>
            <li class="page-item active d-none d-md-block" aria-current="page"><span class="page-link"><?php echo e($page); ?></span></li>
        <?php else: ?>
            <li class="page-item d-none d-md-block"><button type="button" class="page-link" wire:click="gotoPage(<?php echo e($page); ?>)"><?php echo e($page); ?></button></li>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>

If there is a way after calling of gotoPage to call my lazyImagesInit function?

Thanks!

Share Improve this question asked Jul 27, 2020 at 6:32 mstdmstdmstdmstd 3,17722 gold badges86 silver badges192 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Override the goToPage() method on your ponent -

public function gotoPage($page)
{
    $this->page = $page;

    $this->emit('goToPage');
}

Now listen for the goToPage event in JavaScript and call the lazyImagesInit function -

<script>
window.livewire.on('goToPage', () => {
    lazyImagesInit();
});
</script> 
发布评论

评论列表(0)

  1. 暂无评论