vue 動態綁定背景圖片


html

<div class="racetm" :style="{backgroundImage: 'url(' + (coverImgUrl ? coverImgUrl : baseImg) + ')', backgroundSize:'100% 100%', backgroundRepeat: 'no-repeat'}">

</div>

 

畫重點

backgroundSize:'100% 100%'  背景圖片大小 必須這么寫 x軸 y軸 才能100覆蓋
backgroundRepeat: 'no-repeat' 背景圖片不重復
 
        

script  動態賦值

<script>
    export default {
        name: "racehome",
        data(){
            return{ baseImg: require('../../assets/images/other/campain_bg.jpg'), coverImgUrl: '',
            }
        },
        methods:{
            _getracerule(){
                getracerule({id: this.id},{'token':Cookies.get('token'),'platform': 'web'}).then((data)=>{
                    this.rule=data.rule;
                    this.coverImgUrl = data.bg_url;
                })
            },
    }
</script>

 

css

    .racetm
            width: 100%
            height:100%;
            background:#fff

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM