Skip to content

Commit

Permalink
feat:新增问题
Browse files Browse the repository at this point in the history
  • Loading branch information
984507092 committed Apr 30, 2024
1 parent f6e4b8d commit e26998f
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions docs/view/problem/实现选中当前项.md
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>
```

0 comments on commit e26998f

Please sign in to comment.