vue系列文章(10)vue实战项目demo

 

我们要实现的图类似于下面的这样:

 

点击使劲敲,下面的进度条进行减少,敲完后出现下面的图片。同时使劲敲的button消失,恢复原状后变成最上面的图。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Vue.js</title>
	<script src="https://cdn.jsdelivr.net/npm/vue"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
	
</head>
<body>
	<div id="app">
		<h1>vue demo案例一</h1>
		<div id="bag" v-bind:class="{burst: ended}">
			
		</div>

		<div id="bag-health">
			<div v-bind:style="{width: health +'%'}"></div>
		</div>

		<div id="control">
			<button v-on:click="punch" v-show="!ended">
				使劲敲
			</button>
			<button v-on:click="restart">
				恢复原状
			</button>
		</div>
	</div>
	<script type="text/javascript" src="app.js"></script>
</body>
</html>

app.js

new Vue({
	el: '#app',
	data: {
		health: 100,
		ended: false
	},
	methods: {
		punch: function() {
			this.health -= 20;
			if(this.health <= 0){
				console.log(this.ended)
				this.ended = true;
			}
		},
		restart: function() {
			this.health = 100;
			this.ended = false;
		}
	},
	computed: {
		
	}
});

 style.css

#bag {
	width: 200px;
	height: 500px;
	margin: 0 auto;
	background: url(img/bag.png) center no-repeat;
	background-size: 80%;
}
#bag.burst {
	background-image: url(img/bag-burst.png);
}
#bag-health{
	width: 200px;
	border: 2px #000 solid;
	margin: 0 auto 20px auto;
}
#bag-health div{
	height: 20px;
	background: crimson;
}
	
#control{
	width: 200px;
	margin: 0 auto;

}	
#control button{
	margin-left: 20px;
}

   Vue系列文章目录 

  1. vue系列文章(1):对象绑定,属性绑定
  2. Vue系列文章(2)事件绑定,鼠标点击事件
  3. vue系列文章(3):事件修饰符
  4. Vue系列文章(4)键盘事件及键盘修饰符
  5. vue系列文章(5)双向数据绑定
  6. vue系列文章(6)计算属性computed
  7. vue系列文章(7)动态CSS类型绑定
  8. vue系列文章(8)条件渲染
  9. vue系列文章(9)v-for条件循环
  10. vue系列文章(10)vue实战项目demo
  11. vue系列文章(11):初始化多个实例对象
  12. vue系列文章(12)初始组件的应用
  13. Vue系列文章(13)vue cli脚手架
  14. vue系列文章(14)vue-cli脚手架,组件嵌套,全局组件注册和局部组件注册
  15. vue系列文章(15)属性传值props
  16. vue系列文章(16)传值和传引用的类型和区别
  17. vue系列文章(17)利用事件传递将子组件值传递给父组件
  18. vue系列文章(18)vue生命周期
  19. vue系列文章(19)vue路由配置
  20. vue系列文章(20) vue网络请求vue-resource

 如果上面文章对你有用,打赏下我吧@*@

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

互联网极客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值