繁体   English   中英

从 EmberJS 中的另一个 JS 文件调用 JS 函数

[英]Calling a JS functions from another JS file in EmberJS

我目前在 emberJS 工作,我需要在 app/components/mycomponent.js 的 public/myjs.js 中的 JS 文件中调用 function。 它说找不到名为 public/myjs.js 的模块

在 app/component/mycomponent.js 中,这是我的以下代码: import functions from../../public/myjs.js

我也试过这个仍然不起作用: const functions = require("myjs");

谢谢你:)

public中的文件无法在文件顶部导入(通过正常的import X from Y ),它们与构建系统分开。

公用文件夹直接复制到您的dist目录中。

所以有几个访问myjs.js的选项:

  • 使用await import('/myjs.js') -- 本机动态导入将从公共文件夹加载 JS 文件。 记下这里的前导斜线。
  • 将 myjs.js 移动到app文件夹中,然后import X from 'my-app/myjs';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM