关于vue和springboot项目的应用上下文和端口配置

  • 端口配置:

    vue项目config目录下的index.js中port行改为你想要的端口号,注意该行后面有注释:“can be overwritten by process.env.PORT, if port is in use, a free one will be determined”,vue项目运行时能自行决定能运行的空闲的端口号

  • 应用上下文配置:

    在项目下建一个vue.config.js文件,设置文件中publicPath行值为(比如,“/mac/”),就设置了应用上下文,在npm run dev之后可以访问http://localhost:port/mac/路径。

    如果你不想要路径中有井号(“#”),在src/router/index.js中设置router的mode为"history",代码实例如下

const router = new VueRouter({
    mode: 'history',
    routes: routes
})

springboot项目的配置可以在application.yml中做出来

server:
  port: 8081
  servlet:
    context-path: /map/

参考链接

1

配置参考-vue.config.js-publicPath

2

vue地址去掉 #