如下所示:
<!DOCTYPE html>
<html>
<head>
< charset="UTF-8">
< ></ >
< type="text/ " src="js/vue.js" ></ >
<style>
#bag{
width: 200px;
height: 500px;
margin: 0 auto;
background: url(img/piao11.jpg) center no-repeat;
background-size: 80%;
}
.burst{
background-image: url(img/piao12.jpg) !important;
background-size: 80%;
}
#bag-health{
width: 200px;
border: 2px solid #000000;
margin: 0 auto 20px auto;
}
#bag-health div{
height: 20px;
background: crimson;
}
#controls{
width: 200px;
margin: 0 auto;
}
#controls button{
margin-left: 23px;
}
</style>
</head>
<body>
<div id="app">
<!--当前图片-->
<div id="bag" :class='{burst:ended}'></div>
<!--进度情况-->
<div id="bag-health">
<div :style="{width:health + '%'}"></div>
</div>
<!--控制按钮-->
<div id="controls">
<button @click='punch' v-show='!ended'>使劲敲</button>
<button @click='restart'>重新开始</button>
</div>
</div>
< >
new Vue({
el:"#app",
data:{
health:100,
ended:false
},
methods:{
punch:function(){
this.health -= 10;
if (this.health<=0) {
this.ended = true
}
},
restart:function(){
this.health = 100;
this.ended = false
}
},
computed:{
}
})
</ >
</body>
</html>
以上这篇vue动态改变背景图片demo分享就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
-
springboot数据库主从方案
2026-05-18栏目: 教程
-
如何查找前置补丁-Windows安装补丁提示需要安装前置补丁
2026-05-18栏目: 教程
-
月活用户达7.55亿,阿里淘系如何在后流量时代引爆用户增长? | 9月17号栖夜读
2026-05-18栏目: 教程
-
B树和B+树索引原理
2026-05-18栏目: 教程
-
汇编(八)[bx] 、Loop指令
2026-05-18栏目: 教程
