重要部分
<body>
<div class="box">
<div class="bok">
<div class="dd" :style="{width:index+'%'}"><span>{{index}}%</span></div>
</div>
<button @click="index=25">设置25%</button>
<button @click="index=50">设置50%</button>
<button @click="index=75">设置75%</button>
<button @click="index=100">设置100%</button>
</div>
<!-- vue 框架 -->
<script src="./vue.2.7.16.js"></script>
<script>
const box = new Vue({
el:'.box',
data:{
index:10
}
})
</script>
</body>
全部代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 500px;
height: 200px;
margin: auto;
}
.bok{
margin:auto;
margin-top: 30px;
width:500px;
height:40px;
background-color: black;
border-radius:30px ;
border: 5px solid rgb(0, 0, 0);
}
.bok .dd{
width:20%;
height: 40px;
background-color: aqua;
border-radius: 20px;
position: relative;
transition: all 0.6s;
}
.bok .dd span{
position: absolute;
right: -10px;
top: 45px;
font-size: 20px;
font-weight: 600px;
}
button{
font-size: 17px;
margin-top: 30px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="box">
<div class="bok">
<div class="dd" :style="{width:index+'%'}"><span>{{index}}%</span></div>
</div>
<button @click="index=25">设置25%</button>
<button @click="index=50">设置50%</button>
<button @click="index=75">设置75%</button>
<button @click="index=100">设置100%</button>
</div>
<!-- vue 框架 -->
<script src="./vue.2.7.16.js"></script>
<script>
const box = new Vue({
el:'.box',
data:{
index:10
}
})
</script>
</body>
</html>