美文网首页
Vue 的Style中background的URl地址build

Vue 的Style中background的URl地址build

作者: 果汁密码 | 来源:发表于2019-08-27 18:04 被阅读0次

css代码里使用里这样路径的图片:

 background: url('../assets/images/bg01.jpg') no-repeat;

打包过后bg01.jpg会被打包到dist>static>img目录下。

打包之后background: url('../assets/images/bg01.jpg') no-repeat; 会被解析为background: url('static/img/bg01.9be8e15.jpg') no-repeat;

但是这行代码在css文件夹下,css文件夹css文件访问img文件下,需要返回上级目录。所以‘static/img/bg01.9be8e15.jpg'目录是错误的。

解决办法:

在项目的build/utils.js文件里添加

publicPath:'../../'// 解决Vue打包后背景图片路径错误问题

相关文章