子路径部署 如 http://xxxx.com/admin
1.修改.env.production
#修改.env.production
#在尾行加
BASE_API = '/admin/'
2.vue.config.js修改
#vue.config.js修改
publicPath: process.env.NODE_ENV === "production" ? process.env.BASE_API : "/",
outputDir: process.env.NODE_ENV === "production" ?'.'+process.env.BASE_API:'dist',
3.修改/src/router/index.js
#修改/src/router/index.js
export default new Router({
mode: 'history', // 去掉url中的#
base: process.env.NODE_ENV === "production"?process.env.BASE_URL:"",
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
3.修改/src/layout/components/Navbar.vue
修改退出登录方法logout
#修改/src/layout/components/Navbar.vue
#修改退出登录方法logout
async logout() {
this.$confirm('确定注销并退出系统吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
location.href = process.env.NODE_ENV === "production"?process.env.BASE_URL+'index':'/index';
})
}).catch(() => {});
}
4.打包
注意修改后端接口
#打包
#注意修改后端接口
npm run build:prod
5.nginx配置
#nginx配置
#新增
#/www/admin/ 打包后的文件丢到这里
location /admin/ {
try_files $uri $uri/ /admin/index.html;
index index.html index.htm;
alias /www/admin/;
}
#接口
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}