laravel - 如何将前端库连接到laravel?
问题描述
在 laravel 上开发时如何正确连接第三方插件?
我需要 fullpage.js 库
- 通过 npm 下载
- 在 resources/js/bootstrap.js 文件中我添加了 require ('fullpage.js');
在我添加的 resources/js/app.js 文件中
$ (document) .ready (function () { $ ('.js-fullpage').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');
解决方案
你能试着把它包括进去吗
require('fullpage')
或者您可以尝试传递完整路径
推荐阅读
- python - 使用 Spark 的 Conda 环境
- macos - 在进行顺序 C 调用时,在 MacOS 上的 x86 程序集中出现堆栈对齐错误?
- javascript - React Native 使用渲染道具创建自定义模式
- sql - 交易功能的完美数据库设计
- java - 有向图最短路径源到目的地 Dijkstra
- php - 我需要这个 $LoadId=implode(',',array_filter($_POST["load"])); 的输出 看起来像这样 ('7209','7210')
- windows - 脚本在windows中更改10,000个文件夹的文件夹名称
- java - 从哈希图中打印一个值到屏幕 - 一次打印多个值?
- c# - 使用 ASP.NET MVC 从列表创建下拉字段表单
- java - Android Studio:地理定位不起作用。无法在 Webview 中获取地理位置