首页 > 解决方案 > 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')

是什么导致了这个问题?任何帮助表示赞赏。

标签: javascriptfirebasevue.jsvuejs2firebase-hosting

解决方案


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

推荐阅读