vue2.0使用:style绑定backgroundImage失败

<div id="box" style="width:100px;height:100px;"
   :style="{backgroundImage: 'url('+'http://i2.s2.dpfile.com/pc/833992a42d3393b06396ad47684624d0(278x200)/thumb.jpg'+')'}"
   ></div>
   

请问这样写有什么问题吗,绑定失败了,在dom上没有这个style属性

阅读 4.8k
1 个回答

已定位到问题所在,链接有()会和css的url()冲突,需要再用一层引号将其包住

<div id="box" style="width:100px;height:100px;"
   :style="{backgroundImage: 'url(\''+'http://i2.s2.dpfile.com/pc/833992a42d3393b06396ad47684624d0(278x200)/thumb.jpg'+'\')'}"
   ></div>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题