如何将npm包中的JS文件包含到Nuxt.js中的单独页面

时间:2019-03-04 14:29:27

标签: javascript vue.js npm nuxt.js

我有几个serverinfo LifecyclestartDate ExtendedSupportEnddate servicepacksupportenddate servicepack Microsoft Windows Server 2008 R2 Enterprise 2009-10-22 NULL 2020-01-14 Service Pack 1 Microsoft Windows Server 2008 R2 Standard 2009-10-22 NULL 2020-01-14 Service Pack 1 Microsoft® Windows Server® 2008 Standard 2008-05-06 NULL 2011-04-09 Service Pack 1 Microsoft® Windows Server® 2008 Enterprise 2008-05-06 NULL 2020-01-14 Service Pack 2 Microsoft® Windows Server® 2008 Standard 2008-05-06 NULL 2020-01-14 Service Pack 2 Microsoft Windows Server 2012 Standard 2012-10-30 NULL 2023-10-10 Service Pack 2 Microsoft Windows Server 2012 R2 Standard 2012-10-30 NULL 2023-10-10 Service Pack 2 Microsoft Windows Server 2012 Datacenter 2012-10-30 2018-10-09 2023-10-10 Microsoft Windows Server 2012 R2 Datacenter 2012-10-30 2018-10-09 2023-10-10 Microsoft Windows Server 2016 Standard 2016-10-15 2022-01-11 2027-01-12 Microsoft Windows Server 2016 Datacenter 2016-10-15 2022-01-11 2027-01-12 Microsoft® Windows Vista™ Enterprise 2007-01-25 NULL 2010-04-13 Microsoft Windows 7 Enterprise 2007-01-25 NULL 2020-04-13 Service Pack 1 Microsoft Windows 8.1 Entreprise 2013-11-13 NULL 2023-07-11 Microsoft® Windows Vista™ Entreprise 2007-01-25 NULL 2010-04-13 Microsoft Windows 7 Entreprise 2007-01-25 NULL 2020-04-13 Service Pack 1 Microsoft Windows 8.1 Entreprise 2013-11-13 NULL 2023-07-11 Microsoft Windows 10 Enterprise 1900-01-01 1900-01-01 2019-10-08 15063 Microsoft Windows 10 Entreprise 1900-01-01 1900-01-01 2019-10-08 15063 Microsoft Windows 10 Entreprise 1900-01-01 1900-01-01 2020-04-14 16299 Microsoft Windows 10 Entreprise 1900-01-01 1900-01-01 2020-11-10 17134 Microsoft Windows 10 Enterprise 1900-01-01 1900-01-01 2020-11-10 17134 Microsoft Windows 10 Enterprise 1900-01-01 1900-01-01 2021-05-10 17763 Microsoft Windows 10 Entreprise 1900-01-01 1900-01-01 2021-05-10 17763 软件包,这些软件包包含要包含在我的Nuxt.js项目页面中的客户端脚本。我尝试用以下方法做到这一点:

npm

但收到<script> export default { head: { script: [ { src: "gojs/release/go.js", type: "text/javascript" } ] }, // ... } </script> 错误。正确的方法是什么?

1 个答案:

答案 0 :(得分:0)

通常,import-打开模块(例如,使用import go from 'gojs')并在代码中使用它是构建包含该依赖项所需要做的全部工作。无需添加标题即可加载NPM模块。

MyFoo.vue中的示例:

<script>
import go from 'gojs'

export default {
  mounted() {
    const $ = go.GraphObject.make;
    const myDiagram =
      $(go.Diagram, "myDiagramDiv",
        {
          "undoManager.isEnabled": true
        });

    ...
  }
}
</script>

demo