How to add external js file in Nuxt?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 01:10:26

问题


I have js file called script.js in assets/js. Tried to include in nuxt.config.js like below:

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

But getting 'GET http://127.0.0.1:3000/assets/js/script.js 404 (OK)'.


回答1:


Simply keep your script.js file into static folder, because static folder treat as root folder.

and change nuxt.config.js configuration file like below

script: [
          { src: '/script.js'}
      ]


来源:https://stackoverflow.com/questions/52495601/how-to-add-external-js-file-in-nuxt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!