javascript - vue生产模式下静态资产url中的“localhost”
问题描述
我确实将我的项目部署到 Firebase 托管,但问题是我在某些请求图像的请求时收到以下错误。但是,我的图像在我的网站上完美显示:
加载资源失败:net::ERR_CONNECTION_REFUSED
请注意,请求中的路径包含http://localhost:8000/img/
而不是http://mydomain/img/
这是我如何定义图像路径的最小示例:
<v-img :src="require('@/assets/img/sellings.png')" />
我确实mode: 'history'
在路由器中启用了历史()模式
同样在 firebase.json 配置中,我确实有以下内容:
"hosting": {
"public": "dist/",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
在vue.config.js
我确实有以下内容:
global.__rootDirname = path.join(__dirname, 'dist')
是什么导致了这个问题?任何帮助表示赞赏。
解决方案
If you are using vue-cli-service
you can use --host
or --public
arguments
$ npx vue-cli-service serve --help
--host specify host (default: 0.0.0.0)
--public specify the public network URL for the HMR client
So try to run
npx vue-cli-service serve --public mydomain
or
npm run serve -- --public mydomain
推荐阅读
- javascript - 使用 javascript 替换 HTML
- windows-7 - 无法 telnet 端口的规则已经建立
- javascript - Angular 8 karma 导入本地 js 文件并读取其内容
- docker - 如何在 docker-compose up (MariaDB) 上加载 dump.sql 文件
- c# - c#将数组类型转换为另一种数组类型,无需复制和迭代
- azure - Azure SAML 用户属性和声明
- javascript - JS 有时无法在 Chrome 和其他浏览器中加载
- peerjs - 如何使用 Peer.on('call') 功能?
- javascript - 为什么在 React 中尝试访问 Hook State 中的嵌套数组时出现错误?
- wordpress - WordPress sha1/MD5 密码