文章目录
前言一、要怎么做?二、使用步骤1.在data中写入数据2.添加背景图到div处总结前言
例如:项目中我们需要动态改变背景图。
一、要怎么做?
示例:1.首先我们要拿到数据中背景图数据
2.然后在你需要的添加背景图div出添加定义的style
二、使用步骤
1.在data中写入数据
代码如下(示例):
data: {//动态背景图片bg: {backgroundImage: "url(" + ("./img/1.png") + ")"}}
2.添加背景图到div处
代码如下(示例):
<div class="coninter" :style="bg"><div class=“center”>这里是内容</div></div>
这里的话coninter是需要自己去设置样式,:style处只是做了一个动态背景图数据切换,.coninter直接使用。
.coninter{width: 100%;height: 20.5rem;background-size: 100%;background-repeat: no-repeat;}
总结
例如:以上就是今天要讲的内容,本文仅仅简单介绍了动态背景图的使用,经供参考