在 Razor Pages 解决方案中使用 Libman 添加的 js 库

问题描述 投票:0回答:1

我是 Razor Pages 开发新手,在我的项目中使用

Three.js
(由 Libman 添加)时遇到问题。我使用 Libman 添加了 Three.js(默认解决方案配置,以前从未使用过 libman,但看起来包位于正确的位置): (https://i.stack.imgur.com/BrpG4.png)

然后包含在主布局视图中(

_Layout.cshtml
):

<script src="~/lib/three/src/Three.js"></script>
<script src="~/lib/three/examples//jsm/controls/OrbitControls.js"></script>

但是F12控制台出现错误:

Uncaught SyntaxError: Cannot use import statement outside a module

错误指出之前包含的文件:

Three.js:1
OrbitControl.js:1

Libman内容:

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "provider": "cdnjs",
      "library": "[email protected]",
      "destination": "wwwroot/lib/p5.js/"
    },
    {
      "provider": "unpkg",
      "library": "[email protected]",
      "destination": "wwwroot/lib/font-awesome/"
    },
    {
      "provider": "unpkg",
      "library": "[email protected]",
      "destination": "wwwroot/lib/three/"
    },
  ]
}

我发现的建议之一是添加

type="module
但这让我很困惑 - 在哪里添加?我没有
package.json
文件,因为我使用的是 Libman

有谁知道如何解决吗?

我希望使用

Three.js
库配置 Razor Pages,这样我就可以在其中一个页面中使用 3D 图形

asp.net-core three.js razor-pages libman
1个回答
0
投票

您将

type="module"
添加到脚本标签:

<script src="~/lib/three/src/Three.js" type="module"></script>
<script src="~/lib/three/examples//jsm/controls/OrbitControls.js" type="module"></script>
© www.soinside.com 2019 - 2024. All rights reserved.