VUE v-bind动态绑定background背景图片不显示问

2020-06-08  本文已影响0人  Wanlly

我懒,所以没有绑定失败的例子。

v-bind绑定背景图片,该容器(例如div)必须要设有width和height!不然你试试

正确绑定背景图片方式如下,直接上代码:

<template>

  <div id="app">

    <div

      class="right-con"

      :style="{backgroundImage: 'url(' + imgUrl + ')', backgroundSize:'500px 500px', height:'500px', width:'500px'}"

    ></div>

  </div>

</template>

<script>

export default {

  name: "App",

  data() {

    return {

      imgUrl: require("./assets/123.jpg")

    };

  }

};

</script>

效果图:

上一篇 下一篇

猜你喜欢

热点阅读