【Vue3】解决Vue打包后上传服务器 资源路径加载错误

问题:
我这里在打包Vue之后将

打包后的dist 上传至服务器站点根目录内子目录 名为 "adminstore" ,
但是当我通过域名打开站点后发现 资源加载路径内并没有携带 子目录 "adminstore" 文件名称
错误:http://your website domain/js/app.5738021f.js 
正确:http://your website domain/adminstore/js/app.5738021f.js
 

 

原因:在Vue项目中,如果打包后的文件放在了站点根目录的子目录下,而资源的寻找路径却是基于站点根目录,可能会导致资源加载错误

解决方法:
在Vue项目的 "vue.config.js" 文件内 使用 “publicPath
” 属性告诉他 打包你的子目录文件名

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  publicPath: '/adminstore/'
})

猜你喜欢

转载自blog.csdn.net/m0_64494670/article/details/134586964