遇到過這種情況,調試的時候圖片是存在的,能夠在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')+')'}">
至於爲什麼我還是不知道,有哪位大佬知道了可以告訴我嗎_(:з」∠)_