Laravel 5 加载和使用Laravel 5.7/Bootstrap 4.3中的Swiper 4.4.6
我试图找到最好的方法来使用基于Laravel5.7网站的Bootstrap4中的Swiper 使用Laravel 5 加载和使用Laravel 5.7/Bootstrap 4.3中的Swiper 4.4.6,laravel-5,bootstrap-4,swiper,Laravel 5,Bootstrap 4,Swiper,我试图找到最好的方法来使用基于Laravel5.7网站的Bootstrap4中的Swiper 使用npm安装Swiper在已安装的Swiper中安装Swiper 在app.js中我有: require('./bootstrap'); require('swiper'); require('./custom'); 引导和自定义与app.js一样位于resources/js中。Swiper安装在/node_模块中 在custom.js中 var ProjectSwiper = new Swiper
npm安装Swiper
在已安装的Swiper中安装Swiper
在app.js中我有:
require('./bootstrap');
require('swiper');
require('./custom');
引导和自定义与app.js一样位于resources/js中。Swiper安装在/node_模块中
在custom.js中
var ProjectSwiper = new Swiper('.swiper-container', {
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
})
以上所有文件都使用npm run watch
正确加载和编译,此处没有错误
尽管如此,当浏览器控制台显示
ReferenceError:未定义Swiper
我在这里遗漏了什么?试着像这样加载Swiper:
var Swiper = require('swiper');
或作为ES模块:
import Swiper from 'swiper';
您还可以决定将其加载到boostrap.js中,其他库也将在其中加载:
window.Swiper = require('swiper');
这段代码可以工作。前两个选项相同错误:Swiper未定义,第三个选项显示:TypeError:Swiper不是构造函数(用作bootstrap.js中的最后一行)
window.Swiper = require('swiper').default;