【发布时间】:2019-02-19 22:18:07
【问题描述】:
在laravel上开发时如何正确连接第三方插件?
我需要 fullpage.js 库
- 通过 npm 下载
- 在 resources/js/bootstrap.js 文件中我添加了 require ('fullpage.js');
-
在我添加的 resources/js/app.js 文件中
$(文档).ready(函数(){ $ ('.js-fullpage')。完整页面 ({}); });
我启动项目并在控制台中看到
app.js: 4655 jQuery.Deferred exception: $ (...). fullpage is not a function TypeError: $ (...). fullpage is not a function
at HTMLDocument. <anonymous> (http: // localhost: 3000 / js / app.js: 770: 21)
at mightThrow (http: // localhost: 3000 / js / app.js: 4371: 29)
at process (http: // localhost: 3000 / js / app.js: 4439: 12) undefined
app.js: 770 Uncaught TypeError: $ (...). fullpage is not a function
好像它没有看到连接它是一个库..
通常我来自 resources/js/app.js 的调用代码是为什么你高于 resources/js/bootstrap.js,尽管它们以不同的顺序连接
我的引导文件
try {
window.$ = window.jQuery = require('jquery');
} catch (e) {
}
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found:https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
require('fullpage.js');
【问题讨论】:
-
请您将
bootstrap.js文件添加到您的问题中。 -
@RossWilson 添加了
-
您的
app.js文件中的$ ('. js-fullpage'). fullpage ({});是在require('./bootstrap')之前还是之后? -
@RossWilson 在我的 app.js 之后:require('./bootstrap'); $(document).ready(function () { $('.js-fullpage').fullpage(); });