Vue项目打包本地打开index报错Failed to load resource: net::ERR_FILE_NOT_FOUND

原因:打包后的文件要在服务器中运行 解决方法:放在服务器中打开,依次在终端执行下面命令

1.npm install http-server -g       
2.cd dist       
3.http-server

另外,本地打开方法:

1)vue cli2 将config文件夹内index.js文件中 build的assetsPublicPath的’/’改为’./’
2)vue cli3 在项目根目录内vue.congfig.js文件(如没有,自行创建)加上如下代码

module.exports = { 
	publicPath: './' 
}

注意:本地打开,需要把路由的mode: 'history’注释掉

你可能感兴趣的:(Vue)