如何解决laravel 8 将某些 javascript 文件包含到其他 js 文件中
我有两个文件,一个是名为 app.js
的主 js 文件,还有一个文件,用于存储我所有的 js 函数,名为 functions.js
。如下图所示。
但我想将 functions.js
文件包含到 app.js
文件中。所以我用谷歌搜索了如何做到这一点,这就是人们所说的:
但是我的 npm run dev 说该文件不存在。但是路径是正确的。我在这里做错了什么,还有其他方法吗?
解决方法
您可以简单地在任何您想创建的地方创建文件,然后导出一些属性或方法,然后将它们导入您的 app.js file
或您需要的任何文件中。像这样:
//new_file.js
export const jokes = function() {
return ['funny','not really funny','boring']
}
export const heading = 'some global heading to be reused.'
在你的 app.js 文件中:
import { jokes,heading } from 'new_file.js'//specify actual path here .
console.log(jokes) // ['funny','boring']
console.log(heading)//some global heading to be reused.
This tutorial might be helpful too .
http://www.2ality.com/2014/09/es6-modules-final.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。