LaravelJavaScript需要完美的滚动条
我试图在我的LaravelJavaScript中使用jquery pulginLaravelJavaScript需要完美的滚动条,javascript,laravel,laravel-mix,perfect-scrollbar,Javascript,Laravel,Laravel Mix,Perfect Scrollbar,我试图在我的LaravelJavaScript中使用jquery pulgin完美的滚动条。所以我跑了 npm install perfect-scrollbar 在我的Javascript文件的第1行(位于resources/assets/Javascript/material dashboard/myfile.js下),我需要这个插件 require('perfect-scrollbar'); myscript.js是使用require('./material dashboard/mys
完美的滚动条。所以我跑了
npm install perfect-scrollbar
在我的Javascript文件的第1行(位于resources/assets/Javascript/material dashboard/myfile.js
下),我需要这个插件
require('perfect-scrollbar');
myscript.js
是使用require('./material dashboard/myscript.js')
现在浏览器控制台告诉我
Uncaught TypeError: $(...).perfectScrollbar is not a function
这些资产是用
npm run dev
myscript.js的内容
require('perfect-scrollbar');
(function() {
isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;
if (isWindows) {
// if we are on windows OS we activate the perfectScrollbar function
$('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar();
$('html').addClass('perfect-scrollbar-on');
} else {
$('html').addClass('perfect-scrollbar-off');
}
})();
怎么了
谢谢你的帮助 根据,要使用插件初始化元素,应执行以下操作:
import PerfectScrollbar from 'perfect-scrollbar';
new PerfectScrollbar(".sidebar .sidebar-wrapper");
new PerfectScrollbar(".main-panel");
import PerfectScrollbar from 'perfect-scrollbar';
$.fn.perfectScrollbar = function (options) {
return this.each((k, elm) => new PerfectScrollbar(elm, options || {}));
};
$('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar();
如果要使用require
而不是import,可以执行以下操作:
let PerfectScrollbar = require('perfect-scrollbar').default;
最后,该插件看起来不像是要在开箱即用的jQuery
,但是,如果您想像在文章中一样使用jQuery
,可以执行以下操作:
import PerfectScrollbar from 'perfect-scrollbar';
new PerfectScrollbar(".sidebar .sidebar-wrapper");
new PerfectScrollbar(".main-panel");
import PerfectScrollbar from 'perfect-scrollbar';
$.fn.perfectScrollbar = function (options) {
return this.each((k, elm) => new PerfectScrollbar(elm, options || {}));
};
$('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar();
为了简化您的工作,在bootstrap.js文件下
需要(“完美滚动条”);
只需将其更改为
window.PerfectScrollbar=require('perfect-scrollbar')。默认值;你就可以走了。只有在使用带有bootstrap.js的laravel中的编译资源时,才能回答问题。您是否可以添加用于初始化它的代码,即$(…)。perfectScrollbar
代码?内容已添加