-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# 实现当前项选中前面想也选中 | ||
|
||
主要是通过 css 来实现 ,判断当前选中的项大于当前之前的所有项进行选中 | ||
|
||
通过 “ :class="{'active':activeIndex==option,'startactive': option < activeIndex}" ” 实现的效果 | ||
|
||
```html | ||
|
||
<template> | ||
<div class="wrapper-nps"> | ||
<div class="item_nps_config"> | ||
<div | ||
class="item_nps" | ||
:class="{'active':activeIndex==option,'startactive': option < activeIndex}" | ||
v-for="(option,index) in list" | ||
:key="option" | ||
@click="handleClick(option)" | ||
>{{option}}</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
activeIndex: -1, | ||
list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
}; | ||
}, | ||
mounted() {}, | ||
methods: { | ||
handleClick(item) { | ||
this.activeIndex = item; | ||
} | ||
} | ||
}; | ||
</script> | ||
<style lang="scss" scope> | ||
.wrapper-nps { | ||
width: 100%; | ||
height: 100%; | ||
box-sizing: border-box; | ||
padding: 0 15rpx; | ||
} | ||
.item_nps_config { | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-top: 100px; | ||
.item_nps { | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
box-sizing: border-box; | ||
border: 1px solid #eee; | ||
margin: 0 5px; | ||
cursor: pointer; | ||
} | ||
} | ||
.active { | ||
background-color: aqua; | ||
color: #fff; | ||
} | ||
.startactive { | ||
background-color: rgb(253, 123, 100); | ||
color: #fff; | ||
} | ||
</style> | ||
``` |