html:
<div class="colorTag" v-for="(item,index) in predefineColors" :key="item">
<div
class="eachColor"
:style="{ background: item}"
@click="choseColor(index)"
>
<div class="gou" v-show="show[index]">
<img src="@/assets/images/gou.png" alt="" />
</div>
</div>
</div>
css:
.colorTag {
display: inline-block;
}
.colorTag .eachColor {
width: 50px;
height: 50px;
margin-right: 10px;
position: relative;
border-radius: 5px;
}
.colorTag .eachColor:hover {
cursor: pointer;
}
.colorTag .gou {
width: 100%;
height: 100%;
position: absolute;
top: 6px;
left: 7px;
}
js:
show:[false,false,false,false,false,false,false,false],
predefineColors: [
"rgb(228,111,81)",
"rgb(255,203,68)",
"rgb(106,191,64)",
"rgb(61,150,255)",
"rgb(1,218,223)",
"rgb(183,105,243)",
"rgb(93,91,218)",
"rgb(180,76,94)",
],
choseColor(val) {
console.log(val, "选中的");
this.show = [false,false,false,false,false,false,false,false]
this.show[val] = true
this.statusForm.color = this.predefineColors[val]
},