1、前提條件:有配置java環境,下載tomcat后解壓https://tomcat.apache.org/download-80.cgi,得到如下目錄
2、修改vue項目下config/index.js,注意dev和build都要改assetsPublicPath的配置
module.exports = { dev: { ... assetsPublicPath: './', ... }, build: { ... assetsPublicPath: './', ... } }
3、修改路由配置src/router/index.js,增加配置base: '/aoxinwechat/',如果這里不配置,會導致部署的項目首頁訪問一片空白,但不報錯,且引入的文件有正常加載
export default new Router({ //如打包文件存放在Tomcat/webapps/aoxinwechat下, //那么base就這么寫 base: '/aoxinwechat/', mode: 'history', routes: [ ... ] })
4、執行npm run build,將打包生成的dist目錄下的所有東西粘貼到Tomcat/webapps/aoxinwechat路徑下,aoxinwechat是自定義的項目名
5、啟動tomcat,在tomcat下的bin目錄中雙擊startup.bat文件,或者打開命令行去訪問startup.bat,
訪問路徑格式>>ip:port/aoxinwechat,例如:http://localhost:8080/aoxinwechat/,即可訪問到Vue項目。