vue打包发布到服务器出现空白页问题

vue打包发布的时候,经常出现的问题,就是进去是空白的,时而报错,时而不报错

1, vue2.0项目中config文件下index.js中打包配置 // vue3.0+项目中无config文件,在根目录下创建vue.config…js中打包配置

module.exports = {
  publicPath: './', // 根域上下文目录
  outputDir: 'dist', // 构建输出目录
  assetsDir: 'static', // 静态资源目录 (js, css, img, fonts)
  lintOnSave: false, // 是否开启eslint保存检测,有效值:ture | false | 'error'
  runtimeCompiler: true, // 运行时版本是否需要编译
  transpileDependencies: [], // 默认babel-loader忽略mode_modules,这里可增加例外的依赖包名
  productionSourceMap: true, // 是否在构建生产包时生成 sourceMap 文件,false将提高构建速度
  devServer: {
    open: true,
    host: 'localhost',
    port: 8080,
    // https: false,
    // hotOnly: false,
    proxy: {
      // 配置跨域
      '/api': {
        target: 'http://192.168.111.245:9090/',
        ws: true,
        changOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}

特别注意, 若是vue-cli3.0版本y以上则是publicPath: “./”, // 根域上下文目录 若是vue-cli3.0版本以下则是 baseURL:"./"

2,路由配置:router文件夹下index.js

import Vue from 'vue';
import Router from 'vue-router';
import Home from '@/components/Home';
Vue.use(Router);

export default new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },

    {
      path: '/morning',
      name: 'morning',
      component: () => import('../views/morning.vue')
    },
    {
      path: '/afternoon',
      name: 'afternoon',
      component: () => import('../views/afternoon.vue')
    },
    {
      path: '/total',
      name: 'total',
      component: () => import('../views/total.vue')
    }
  ]
});

注意,系统默认是mode:是history,我们只需要把这里注释即可

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值