1.html
<view>
<view class="nav">
<view class="nav-list" v-for="(item,index) in list" :key="item.id" @tap="changeAct(item)">
<view :class="[act==index?'name':'']">
{{item.name}}
</view>
<view :class="[act==index?'line':'']">
</view>
</view>
</view>
<view class="content">
<view class="">
{{content.id}}
</view>
<view class="">
{{content.name}}
</view>
</view>
</view>
2,js
<script>
export default {
data() {
return {
act: 0,
list: [{
id: 0,
name: '吃饭'
},
{
id: 1,
name: '学习'
},
{
id: 2,
name: '睡觉'
}
],
content: ''
};
},
methods: {
changeAct(item) {
this.act = item.id;
this.content = item
}
},
onShow() {
this.content = this.list[0]
}
}
</script>
3.css
<style scoped>
.nav {
height: 100rpx;
display: flex;
align-items: center;
justify-content: space-around;
background-color: rgba(0, 0, 0, .8);
font-size: 30rpx;
color: orange;
letter-spacing: 2.14rpx;
}
.nav-list {
width: 65rpx;
height: 100%;
margin-top: 40rpx;
opacity: .9;
}
.nav-list .name {
color: red;
}
.nav-list .line {
margin-top: 10rpx;
width: 65rpx;
height: 4rpx;
background-color: red;
}
.content {
margin-top: 40rpx;
}
</style>