一、 vue-cli创建项打包后打开页面为空白的问题解决

命令行输入:npm run build

打包出来后项目中就会多了一个文件夹dist,这就是我们打包过后的项目。

二、打包完成后配置会自动生成vue.config.js文件,这个文件非常重要值得你收藏

配置如下:

const path = require("path");
const resolve = function(dir) {
  return path.join(__dirname, dir);
};
module.exports = {
  publicpath: process.env.node_env === "production" ? "./" : "./",
  outputdir: "dist",
  assetsdir: "static",
  lintonsave: true, // 是否开启eslint保存检测
  productionsourcemap: false, // 是否在构建生产包时生成sourcdemap
  chainwebpack: config => {
    config.resolve.alias
      .set("@", resolve("src"))
      .set("@v", resolve("src/views"))
      .set("@c", resolve("src/components"))
      .set("@u", resolve("src/utils"))
      .set("@s", resolve("src/service")); /* 别名配置 */
    config.optimization.runtimechunk("single");
  },
  devserver: {
    // host: "localhost",
    /* 本地ip地址 */
    //host: "192.168.1.107",
    host: "0.0.0.0", //局域网和本地访问
    port: "8080",
    hot: true,
    /* 自动打开浏览器 */
    open: false,
    overlay: {
      warning: false,
      error: true
    },
    /* 跨域代理 */
    proxy: {
      "/api": {
        /* 目标代理服务器地址 */
        target: "http://m260048y71.zicp.vip", //
        // target: "http://192.168.1.102:8888", //
        /* 允许跨域 */
        changeorigin: true,
        ws: true,
        pathrewrite: {
          "^/api": ""
        }
      }
    }
  }
};

第三个问题:router-view中的内容显示不出来。路由history模式

这个坑是当你使用了路由之后,在没有后端配合的情况下就手贱打开路由history模式的时候,打包出来的文件也会是一片空白的情况,
解决:在 router.js 中将 mode: history注释掉

到此这篇关于vue打包后页面出现空白解决办法的文章就介绍到这了,更多相关vue打包页面出现空白内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!