1. The effect to be achieved is as follows:
2. Code implementation:
2.1 html
<template>
<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>
</template>
2.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>
2.3 css
<style scoped>
.nav {
height: 100rpx;
display: flex;
align-items: center;
justify-content: space-around;
background-color: rgba(0, 0, 0, .5);
font-size: 30rpx;
color: #fff;
}
.nav-list {
width: 100rpx;
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;
text-align: center;
}
</style>
ending~