Vue实现的一个简单的Demo

一个你可以看得懂的Demo

二话不说先看效果!

在这里插入图片描述解释一下吧,实现的效果!Punch可以控制红色进度条,Restart就是重新开始。嘻嘻嘻~~~~~,进度条小于等于0时颜色发生Turn down…
懂的都懂!!!

是时候上才艺了

HTML代码

<div id="app">
        <div class="bug" :class="{turn:use}">
        	
        </div>
        <div class="bottom">
        	<div :style="{width:health+'%'}"></div>
        </div>
        <div class="bt">
        	<button @click="punch" v-show="!use">Punch</button>
        	<button @click="restart" >Restart</button>
        </div>
   </div>

JS代码

 <script>
       new Vue({
           el:"#app",
           data:{
           	    health:100,
                use:false,
           },
           methods:{
                punch(){
                    this.health -= 10;
                    if (this.health<=0) {
                    	this.use=true;
                    }

                },
                restart(){
                	this.health=100;
                	this.use=false;
                }
           }
       })
   </script>

CSS代码:

 <style>
        .bug{
        	width: 100px;
        	height:100px;
        	background-color:pink;
        	background-size:80%;
        	margin:0 auto;
        }
        .bug.turn{
        	
        	background-color:yellow;
        	background-size:80%;
        	margin:0 auto;
        }
        .bottom{
        	border:2px #000 solid;
        	width: 100px;
        	margin:10px auto 10px auto;
        }
        .bottom div{
        	height:10px;
        	background-color:red;
        }
        .bt{
        	width: 120px;
        	margin:0 auto;
        }

    </style>

完整代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <style>
        .bug{
        	width: 100px;
        	height:100px;
        	background-color:pink;
        	background-size:80%;
        	margin:0 auto;
        }
        .bug.turn{
        	
        	background-color:yellow;
        	background-size:80%;
        	margin:0 auto;
        }
        .bottom{
        	border:2px #000 solid;
        	width: 100px;
        	margin:10px auto 10px auto;
        }
        .bottom div{
        	height:10px;
        	background-color:red;
        }
        .bt{
        	width: 120px;
        	margin:0 auto;
        }

    </style>
</head>
<body>
   <div id="app">
        <div class="bug" :class="{turn:use}">
        	
        </div>
        <div class="bottom">
        	<div :style="{width:health+'%'}"></div>
        </div>
        <div class="bt">
        	<button @click="punch" v-show="!use">Punch</button>
        	<button @click="restart" >Restart</button>
        </div>
   </div>
   <script>
       new Vue({
           el:"#app",
           data:{
           	    health:100,
                use:false,
           },
           methods:{
                punch(){
                    this.health -= 10;
                    if (this.health<=0) {
                    	this.use=true;
                    }

                },
                restart(){
                	this.health=100;
                	this.use=false;
                }
           }
       })
   </script>
</body>
</html>

小结:刚开始学,小白制作,大佬略过!!!!!!

在这里插入图片描述

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值