用数组下标进行判断index默认数组下标 在用if循环进行判断数组元素
<template>
<view>
<view class="choseBox">
<view :class="currentIndex== index?'option':'option2'" class="option" v-for="(item,index) in list"
@click="inChose(index)">{{item}}</view>
<view class="" v-for="(item,index) in info">
<image :src="item.scr" mode=""></image>
<h1>{{item.msg1}}</h1>
</view>
</view>
</view>
</template>
<script>
export default {
name: "pose-option",
data() {
return {
// 分类选项
list: ["全部", "女性", "男性", "其他"],
currentIndex: 0,
info:[{
scr:"../../static/c1.png",
msg1:"撒大大大"
}],info1:[{
scr:"../../static/c2.png",
msg1:"撒大大大"
}],info2:[{
scr:"../../static/c3.png",
msg1:"撒大大大"
}],info3:[{
scr:"../../static/c4.png",
msg1:"撒大大大"
}]
};
},
methods: {
// 分类选项
inChose(index,res) {
this.currentIndex = index
console.log(index)
if(index==0){
this.info=this.info
}else if(index==1)
this.info=this.info1
}
}
}
</script>
<style lang="scss" scoped>
.choseBox {
// 分类选项
// border: #0055ff 1px solid;
width: 100%;
height: 30px;
margin-top: 20rpx;
.option {
width: 118rpx;
height: 42rpx;
background: #6C8CA9;
border-radius: 20px;
margin-left: 20rpx;
float: left;
color: #f7f7f7;
text-align: center;
}
.option2 {
width: 118rpx;
height: 42rpx;
background: #91B8DC;
border-radius: 20px;
margin-left: 20rpx;
float: left;
color: #f7f7f7;
text-align: center;
}
}
</style>