vue绑定背景颜色或背景图片 和 nuxtjs动态设置background-image:

17 篇文章 1 订阅
9 篇文章 0 订阅

v-bind绑定样式表:
----------------------------------------------------------------------------------------------------

HTML写法:
<div class="myItem" style="text-align:center; background-image:url(''); background-size:auto 100% ;background-position:center; background-repeat:no-repeat;" >

v-bind绑定style写法(里面是个json): 
<div class="myItem" :index="index"  :style="{'text-align':'center','background-image':'url('+item.photo+')','background-size':'auto 100%','background-position':'center','background-repeat':'no-repeat'}"  >

<div class="box" :style="{width:width,height:height,backgroundColor:backgroundColor}"></div>

nuxtjs动态设置background-image

  <div :style="{backgroundImage: `url(` + require(`~/assets/ProjectPictures/${this.background}`) + `)`}">

nuxt绑定内联样式 :style="{'title':'里面必须标准的json'}"   里面必须是标准的json格式否则出错
--------------------------------------------------------------------------  
    <div style="float:left;width:27.18%;height:14.2vw; border:1px solid #ccc;background-size:100% 100%;"  :style="{'background-image':'url(\''+require('@/assets/images/index/advantage1.png')+'\')'}"  >
        <nuxt-link to="/freeCoupons" style="display: flex; margin:9vw 2vw auto auto; align-items:center; width: 20vw;border:0px solid #ccc;color:#999;font-size: 10pt;font-weight:bold; line-height:2;" >  test   </nuxt-link>
    </div>  

(注意::style后面是个json,否则会报错!)    

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值