遇到过这种情况,调试的时候图片是存在的,能够在style中看到图片的,但是背景就是无法显示。特别奇怪的是如果不是给整个body加background或者对最外层的div的class加background,都可以添加。
比如随便选中一个类是可以成功的:
.scores{
background: url(../../images/4-2.png) no-repeat;
background-size: 100% 100%;
}
但是如果这个class包裹了整个模板就不行,比如这样就不行:
<template>
<div class="test">
//里面是本来要执行的全部代码
</div>
</template>
<style lang="less">
.test{
background: url(../../images/4-2.png) no-repeat;
background-size: 100% 100%;
}
</style>
为了解决这个情况我在div中使用require直接引入图片就可以,如图:
<div :style="{backgroundImage:'url('+require('../../images/1-0.jpeg')+')'}">
至于为什么我还是不知道,有哪位大佬知道了可以告诉我吗_(:з」∠)_