栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

vue-部署教程

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vue-部署教程

vue部署

项目结构

使用NGINX部署 vue-history模式 router配置

router的index.js文件

// 路由相关
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/pages/login/login"

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
};

const routes = [
    {
        path:'',
        redirect:'/Login'
    },
    {
        path:'/Login',
        name:'Login',
        component:Login
    }
]


const router = new VueRouter({
    routes,
    mode: 'history' 
})
vue.config.js文件
module.exports = {
    configureWebpack: {
        resolve: {
            alias: {
                'network': '@/network',
                'components': '@/components'
            }
        }
    },
    lintOnSave: false,
    publicPath: process.env.NODE_ENV === "production" ? "./" : "/", //重要配置
    devServer: {
        open: true,
        host: '0.0.0.0',
        port: 8081,
        https: false,
        hotOnly: false,
    }
}
nginx配置 nginx.conf
 server {
     listen 8071 ;
     listen [::]:8071 ;
     server_name vue; # 这里是网站的域名
     location / {
       root D:/dist;# /vue/dist/; 打包后的dist目录
       try_files $uri $uri/ @router; # 指向下面的 @router否则会出现 404
       index index.html index.htm;
      }
    # 对应上面的 @router,主要Vue请求并不是真实路径,无法找到文件,需要重定向到 index.html 中,然后交给路由处理
     location @router {
      rewrite ^.*$ /index.html last;
     }
  }
使用SpringBoot部署

可以将前后台放一起部署

vue-hash模式 router配置

router的index.js文件

// 路由相关
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/pages/login/login"

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
};

const routes = [
    {
        path:'',
        redirect:'/Login'
    },
    {
        path:'/Login',
        name:'Login',
        component:Login
    }
]


const router = new VueRouter({
    routes,
   // mode: 'history' 
})
vue.config.js文件
module.exports = {
    configureWebpack: {
        resolve: {
            alias: {
                'network': '@/network',
                'components': '@/components'
            }
        }
    },
    lintOnSave: false,
    publicPath:'./', //重要配置
    devServer: {
        open: true,
        host: '0.0.0.0',
        port: 8081,
        https: false,
        hotOnly: false,
    }
}

将打包后的vue项目放入SpringBoot项目的static中

SpringBoot配置

项目结构如下:

pom.xml

引入以下依赖

        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-web
        
application.yml
server:
  port: 8888
  url: localhost
spring:
  mvc:
    static-path-pattern: static/**
    async:
      request-timeout: 200000

访问地址:http://localhost:8888/static/dist/index.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/751621.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号