我正在开发一个项目,该项目有多个包含不同功能的 .js 文件。 我想在 M2.js 中使用 M1.js 中的函数,我正在做的是从 M1.js 中导出函数并在 M2.js 中导入。
导出工作正常,但问题出在我导入函数时。
M1.js
--export {function}
M2.js
--import {function} from './M1.js'
<script type="module" href="{% static 'myapp/M1.js'%}
<script type="module" href="{% static 'myapp/M2.js'%}
上面是在导入时生成以下错误的代码
Loading module from “app.com/static/Invoicing/exif_js” was blocked because of a disallowed MIME type (“text/html”).
我的目录结构是
-Project
|--project
|--Invoicing (App)
|--static
|--Invoicing
|--M1.js
|--M2.js
|--templates
|--etc
|--static
|--etc
最佳答案
尝试将 index.html
中的基本 href 更改为当前目录
改变这个
<base href="/">
对此
<base href="./">
关于Django 中的 Javascript 模块管理(已关闭),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66381165/