vue打包页面空白(最完美的解决办法)

vue打包页面空白,什么都不显示(解决)

当打完包的时候,可以看到它提示一句话

Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won’t work.

这句话的意思就是打包的文件必须要通过服务启动,,直接打开无效。看到这句话就蒙了,不知道怎么改,就去百度了,试了各种方法还是都行不通,找了许久终于找到一个能行的了。

这段操作共需要改三部分

  1. 找到config文件夹下index.js

    build: {
        // Template for index.html
        index: path.resolve(__dirname, '../dist/index.html'),
    
        // Paths
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsSubDirectory: 'static',
        assetsPublicPath: './',   //**这里就是要改的地方,原来是'/',改为'./'**
    
        /**
         * Source Maps
         */
    
  2. 找到build文件夹下utils.js

       // Extract CSS when that option is specified
        // (which is the case during production build)
        if (options.extract) {
          return ExtractTextPlugin.extract({
            use: loaders,
            fallback: 'vue-style-loader',
            publicPath:'../../'     //新加入此行代码
          })
        } else {
          return ['vue-style-loader'].concat(loaders)
        }
      }
    
  3. 找到router下面的index.js

     mode: 'hash', // 把mode设置未hash
    

猜你喜欢

转载自blog.csdn.net/nannanWEB/article/details/83057669