如文档中所述,我更改了基本路线,以便以正确的方式为资产提供服务,如下所示:
const config = {
// Changes the website's base to work on Github pages
routerBase: process.env.NODE_ENV == 'gh_pages' ? '/my-app/' : '/'
};
module.exports = {
router: {
base: config.routerBase
}
}
index.vue
文件夹中pages
中的背景图片显示如下:
.home {
background: url('/background.jpg') no-repeat bottom fixed;
background-size: cover;
color: white;
}
因此,路径应为/my-app/background.jpg
,但不会显示图像,就好像它试图沿着路径/
找到它一样。
我在做什么错?请注意,从index.html
文件夹部署的dist
拥有正确的基础,例如:<base href="/my-app/">
答案 0 :(得分:0)
将URL路径更改为~/static/background.jpg
解决了这个问题,当我尝试从静态文件夹访问静态资产时,这很奇怪,而/background.jpg
应该足够。