【问题标题】:Nuxt.js After npm run generate cannot find filesNuxt.js npm run generate 后找不到文件
【发布时间】:2018-12-31 03:42:32
【问题描述】:

我正在尝试使用 npm run generate 生成我的应用程序 在终端上。我没有收到任何错误,一切都很好。在我的开发服务器中,路由组件等一切正常,但是当我在 dist 文件夹中打开 index.html 时生成后,我无法访问其他页面,chrome 控制台上出现类似的错误。

Failed to load resource: net::ERR_FILE_NOT_FOUND
f8ff67c7350097487a5e.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
e63cddd635f290d15a6f.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
9a1a3c7742fdcce5403a.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
1e056384fb18617ca6a5.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
bde8656.png:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND

我尝试将 dist 文件夹上传到我的 ftp 中,但是太相同了……

这是我的 nuxt.config 文件

const pkg = require('./package')

module.exports = {
  mode: 'universal',

  /*
  ** Headers of the page
  */
  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' }
    ]
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },

  /*
  ** Global CSS
  */
  css: [
  ],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],

  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios',
    // Doc:https://github.com/nuxt-community/modules/tree/master/packages/bulma
    '@nuxtjs/bulma',
    // ['nuxt-validate', {
    //   lang: 'tr',
    //   // regular vee-validate options 
    // }]
  ],
  /*
  ** Axios module configuration
  */
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
  },

  /*
  ** Build configuration
  */
  build: {
    postcss: {
      preset: {
        features: {
          customProperties: false
        }
      }
    },
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {

    }
  }
}

【问题讨论】:

  • 您的项目是否从服务器加载数据?
  • 没有。只有一个 api 调用,我用响应来做一些事情。
  • 如何打开生成的项目?如果您直接在浏览器中打开您的 html 文件,它将无法正常工作。你需要一个http服务器
  • @Aldarund 我已将 dist 文件夹的内容上传到我的 ftp 并且无法正常工作,我认为问题是浏览器在根目录之外搜索 _nuxt 文件夹
  • 您是否通过根域(例如 yourdomain.com)上传和访问它?或 yourdomain.com/somedir ?

标签: vue.js vuejs2 nuxt.js


【解决方案1】:

如果你不是通过域根访问它,你需要在 nuxt 配置中设置它 https://nuxtjs.org/api/configuration-router/#base

export default {
  router: {
    base: '/app/'
  }
}

【讨论】:

    猜你喜欢
    • 2021-03-28
    • 2020-04-05
    • 1970-01-01
    • 2021-03-06
    • 2020-03-06
    • 2022-01-10
    • 2021-04-13
    • 2020-03-24
    • 2018-01-22
    相关资源
    最近更新 更多