如何添加Bootstrap, jQuery, and popper.js 到Laravel 8?

Laravel框架
382
0
0
2022-03-06
标签   Laravel基础
composer require laravel/ui
php artisan ui bootstrap
npm install bootstrap@latest @popperjs/core --save-dev
npm install && npm run dev

在 resources/js/bootstrap.js 改成这样就整合了

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */ 

try {
    window.$ = window.jQuery = require('jquery');
    window.Popper = require('@popperjs/core');
    window.bootstrap = require('bootstrap');

} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */ 

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

最后再运行下 npm run dev