<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js"></script>
<style>
*{
margin:0;
padding:0;
}
.big{
width: 500px;
height: 20px;
background-color:#dedede;
margin-top: 20px;
margin-bottom: 20px;
}
.sm{
width:0;
height: 20px;
background-color:red;
transition:all 1s;
}
button{
width: 100px;
height: 50px;
}
</style>
</head>
<body>
<div id="box">
<pro @pos="pos" :w="w"></pro>
<btn @reduce="reduce" @add="add" :count="w"></btn>
</div>
</body>
<script>
//组件通信
Vue.component("pro",{
props:["w"],
template:"<div class='big' @click='pos($event)'><div class='sm' :style='{width:w+\"%\"}'></div></div>",
methods:{
pos:function(e){
var p=Math.round((e.clientX / 500) * 100);
this.$emit("pos",p)
}
}
})
Vue.component("btn",{
props:["count"],
template:"<div><button @click='reduce'>-</button><button>{{count}}</button><button @click='add'>+</button></div>",
methods:{
reduce:function(){
this.$emit("reduce")
},
add:function(){
this.$emit("add")
},
}
})
var box=new Vue({
el:"#box",
data:{
w:0
},
methods:{
reduce:function(){
this.w--;
if(this.w<0){
this.w=0;
}
},
add:function(){
this.w++;
if(this.w>100){
this.w=100
}
},
pos:function(a){
this.w=a;
}
}
})
</script>
</html>
进度条
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- https://github.com/fems1888/SelfTestLib
- 在这浓浓的鞭炮声中,迎来了这个系列的最后一篇。哈哈~这是多么有纪念意义的春节呀。 今天我们来写一个小小的Demo,...
- CircleProgress 项目中要用到进度百分比跟随进度动的效果,在网上找了一下,没找到合适的,就自己写了一个...