【问题标题】:Include js library in nuxt.config.js with Assets在带有资产的 nuxt.config.js 中包含 js 库
【发布时间】:2021-05-14 07:51:18
【问题描述】:

我正在尝试包含一些 javascript 文件,但由于某种原因,我得到了这个

" GET http://localhost:3000/assets/js/jquery-3.4.1.min.js 中的错误 net::ERR_ABORTED 404(未找到)

如果有人可以帮助我,我不知道这是否是包含 javascript 文件的更好方法。

     head: {
    title: 'streamit',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' }
    ],
    script: [
      { src: '/assets/js/jquery-3.4.1.min.js', type: 'text/javascript' },
    
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/images/favicon.ico' }
    ]
  },

assets/js/jquery-3.4.1.min.js

【问题讨论】:

  • jquery-3.4.1min.js != jquery-3.4.1.min.js

标签: javascript vue.js nuxt.js


【解决方案1】:

像这样尝试并确保 static 文件夹并在其中创建 js floder 并将您的 jquery-3.4.1.min.js 文件放在那里。在你的nuxt.config.js 中放:

script: [
  { src: 'js/jquery-3.4.1.min.js' },
]

【讨论】:

    【解决方案2】:

    我通过添加一个名为 static 的新文件夹来解决此问题,然后将所有 js 文件放入其中

    script: [
          { src: './js/jquery-3.4.1.min.js', type: 'text/javascript' },
        
        ],
    

    【讨论】:

      猜你喜欢
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 2013-08-20
      • 2019-10-31
      • 1970-01-01
      • 2018-12-24
      相关资源
      最近更新 更多