![](/img/trans.png)
[英]Magento 2 - RequireJS config file not importing JS files, no error thrown
[英]load js file in requirejs-config.js in magento2
如何在requirejs中加載這個js文件?
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
我的 requirejs-config.js 文件=?
var config = {
paths: {
modelviewer: "Ajith_CustomModule/js/modelviewer.min",
.....
.....
.....
並將此文件加載到我的 phtml 文件中
<script type="module">
require(['jquery'.......,'modelviewer'],function($,..,model){
});
</script>
.....
.....
.....
顯示此錯誤 => Uncaught SyntaxError: Unexpected token 'export'
任何人請幫我解決這個問題。
提前致謝
RequireJS 不支持原生 JS 模塊。 您必須將其作為常規 JS 模塊加載,工作示例:
<script type="module">
import { ModelViewerElement } from 'https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js';
console.log(ModelViewerElement);
</script>
(在 Chrome 96 上測試)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.