0

I need to use Carousel Owl in my Laravel project.
My JS:

import 'owl.carousel/dist/assets/owl.carousel.css';
import 'owl.carousel';

const carouselEl = document.querySelector('.owl-carousel');
var $ = require('jquery');

$(document).ready(function() {
    carouselEl.owlCarousel();
});

webpack.mix.js:

mix.webpackConfig((webpack) => {
    return {
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'window.jQuery': 'jquery'
            }),
        ],
    };
});

When I compiled this, there was error:

carouselEl.owlCarousel is not a function.
Blablabla
  • 175
  • 3
  • 9
  • https://stackoverflow.com/a/28390573/4575350 – STA Sep 03 '20 at 09:52
  • can u put your blade.php so can check how u are include `app.js` – Kamlesh Paul Sep 03 '20 at 09:55
  • Webpack.mix.js: mix.js('resources/js/app.js', 'public/js') .js('resources/js/script.js', 'public/js') .sass('resources/sass/app.scss', 'public/css'); Blade: Everything in this script works, I have issue just with carousel – Blablabla Sep 03 '20 at 09:58

1 Answers1

0

replace

const carouselEl = document.querySelector('.owl-carousel');

$(document).ready(function() {
    carouselEl.owlCarousel();
});

with

$(document).ready(function() {
    $(".owl-carousel").owlCarousel();
});

your code is not working becouse carouselEl it is just a html element instance so u can call owlCarousel() to that

Kamlesh Paul
  • 11,778
  • 2
  • 20
  • 33