0

I'm new to Laravel and VueJS, and I want to include JavaScript files in my project. Can someone please tell me how to do that? I watched a video on YouTube and got a solution, but sometimes it's not working and it's not good practice to load JavaScript files like this. Please suggest any other options.

      var src = [
            import.meta.env.VITE_APP_URL +'/assets/frontend/vendor/jquery/jquery-3.2.1.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/animsition/js/animsition.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/bootstrap/js/popper.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/bootstrap/js/bootstrap.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/select2/select2.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/daterangepicker/moment.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/daterangepicker/daterangepicker.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/slick/slick.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/slick-custom.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/parallax100/parallax100.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/MagnificPopup/jquery.magnific-popup.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/isotope/isotope.pkgd.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/sweetalert/sweetalert.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/vendor/perfect-scrollbar/perfect-scrollbar.min.js',
            import.meta.env.VITE_APP_URL + '/assets/frontend/main.js'];

        for (var i = 0; i < src.length; i++) {
            const script = document.createElement('script')
            script.src = src[i];
            script.async = false;
            document.getElementById('scripts').appendChild(script);
        }
    }
3
  • 1
    laravel.com/docs/11.x/vite Commented Jun 28, 2024 at 6:48
  • if i'm using vite to load js file then i'm getting error like "TypeError: Cannot set properties of undefined (setting 'Popper')" Commented Jun 28, 2024 at 7:29
  • You are then not importing Popper properly, check their documentation. I would also recommend skipping Bootstrap and any other jQuery-based code in 2024. Commented Jun 28, 2024 at 8:15

1 Answer 1

0

If you wanna use Vuejs components within blade files of Laravel, this article might help you: https://f24aalam.medium.com/integrating-vue-js-components-in-laravel-a-beginners-guide-cf8414a27d6b

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.