This commit is contained in:
Code12121 2022-10-20 09:41:50 +08:00
parent 19c5534a07
commit 22ae1e28e5
2 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,142 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>商品列表</title>
<style>
*{
margin: 0;
padding: 0;
}
.part{
width: 60%;
margin: 0 auto;
text-align: center;
background-color: aquamarine;
font-size: 18px;
}
.title{
padding: 10px 0;
font-size: 30px;
font-weight: bolder;
}
.ul{
list-style: none;
width: 80%;
margin: 0 auto;
}
.li{
margin: 20px 0;
height: 50px;
background-color: #fff;
display: flex;
}
.li>div{
padding: 0 20px;
color: #000;
}
.li>.left{
text-align: left;
}
.li>.right{
text-align: right;
}
.bottom{
width: 80%;
height: 80px;
border-top: 1px solid #fff;
margin: 0 auto;
display: flex;
font-weight: bolder;
}
.bottom>div,
.li>div{
align-self: center;
flex:1
}
.bottom>div{
padding: 0 20px;
}
.bottom>.left{
text-align: left;
}
.bottom>.right{
text-align: right;
}
.active{
background-color: red;
}
</style>
</head>
<body>
<div id="app">
<div class="part">
<div class="title">商品列表</div>
<div class="ul">
<div class="li" v-for="items,value in list" :class="isColorChanges(value)" @click="isClick(value)">
<div class="left">{{items.item}}</div>
<div class="right">{{items.price}}</div>
</div>
</div>
<div class="bottom">
<div class="left">合计</div>
<div class="right">{{TotalPrice}}</div>
</div>
</div>
</div>
</body>
<script src="../js/vue.min.js"></script>
<script>
const vue=new Vue({
el:"#app",
data:{
list:[
{ item: "联想小新", price: 6599 ,isActive:false},
{ item: "惠普暗影精灵", price: 9900 , isActive: false },
{ item: "联想昭阳", price: 2400 , isActive: false },
{ item: "联想拯救者", price: 8700 , isActive: false },
{ item: "华硕天选", price: 8800 , isActive: false },
{ item: "华硕飞行堡垒", price: 6000 , isActive: false },
{ item: "外星人ROG", price: 12300 , isActive: false}
],
list_index:0,
list_count:0
},
methods: {
/*
设置商品列表当前颜色
*/
isColorChanges(index){
return {active:this.list[index].isActive}
},
isClick(index){
/*传递当前所点击元素的下标值*/
this.list_index=index
/*判断当前的下标所在的元素是否高亮*/
if(this.list[index].isActive==false){
this.list[index].isActive = true
}else{
this.list[index].isActive = false
}
}
},
computed:{
TotalPrice(){
if(this.list[this.list_index].isActive==true){
this.list_count+=this.list[this.list_index].price
}else{
if(this.list[this.list_index].isActive==false&&this.list_index==0){
this.list_count=this.list[this.list_index].price
}
this.list_count -= this.list[this.list_index].price
}
return this.list_count
}
}
})
</script>
</html>

File diff suppressed because one or more lines are too long