美文网首页
vue css引用背景图片问题

vue css引用背景图片问题

作者: minusplus | 来源:发表于2019-08-25 21:11 被阅读0次

在css中的 background 属性中,正常是使用 background: url('../assets/img/hello.png'); 就能引入静态背景图片;
如果服务器上存在前缀的时候: 比如 www.baidu.com/hello/你的项目, 这里的hello就是你的前缀,这时候就会出问题了,背景图片找不到了,下面踢狗两种方法。
一:打开 build 文件夹下的 utils.js
找到如下配置

在这里插入图片描述
添加 publicPath:"../../"
二:直接在组件中导入
如:import hello from "../assets/hello.png" , 并在 template 中动态导入 :style="{background: 'url('+hello+')'}" ; 这样就算服务器上有再多的前缀,也照常能够引入。
或者在 data 中
data(){
    return {
        hello:require("../assets/hello.png"),
    }
},

相关文章

网友评论

      本文标题:vue css引用背景图片问题

      本文链接:https://www.haomeiwen.com/subject/zhikectx.html