Vue3使用vant框架,使用选项卡组件Tab 标签页,用于在不同的内容区域之间进行切换。并动态传递active等于2,使得“已收货”亮起。
Tab 标签页
选项卡组件,用于在不同的内容区域之间进行切换。通过 v-model:active 绑定当前激活标签对应的索引值,默认情况下启用第一个标签。
<template>
<div class="my-order-list">
<div class="head-box">
<van-tabs :active="active" @click-tab="onClickTab">
<van-tab v-for="item in list" :key="item.type" :title="item.name"></van-tab>
</van-tabs>
<div class="list-box" v-for="(item, index) in arrList" :key="index">
<!-- 控制四个组件 : -->
<AfterSalesItem v-if="item.type == 0" :arrList="item.name" class="card"></AfterSalesItem>
<wait-receive-goods v-if="item.type == 1" class="card"></wait-receive-goods>
<receive-goods v-if="item.type == 2" class="card"></receive-goods>
<sale-list-view v-if="item.type == 3" class="card"></sale-list-view>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from "vue"
import AfterSalesItem from './components/item.vue' //引入组件
import WaitReceiveGoods from './components/wait-receive-goods.vue' //引入组件
import ReceiveGoods from './components/receive-goods.vue' //引入组件
import SaleListView from './components/sale-list.vue' //引入组件
import { useRoute } from 'vue-router';
const route = useRoute();
const active = ref();
//定义数组
const list = ref([
{ name: "待发货", type: 0 },
{ name: "待收货", type: 1 },
{ name: "已收货", type: 2 },
{ name: "售后", type: 3 }
])
const arrList = ref([
{ name: "待发货", type: 0 }
])
const onClickTab = ({ title }) => {
//通过点击返回的title('待发货,已发货....'),来匹配对应的active也就是type
let type = 0
if (title == "待发货") {
type = 0
} else if (title == "待收货") {
type = 1
} else if (title == "已收货") {
type = 2
} else if (title == "售后") {
type = 3
}
arrList.value.forEach(i => {
i.name = title
i.type = type
})
}
onMounted(() => {
//获取“订单售后”传进的active值
active.value = eval("(" + route.query.active + ")");
// 根据active来判断,并匹配其代表的含义
let title = "待发货"
if (active.value == 0) {
title = "待发货"
} else if (active.value == 1) {
title = "待收货"
} else if (active.value == 2) {
title = "已收货"
} else if (active.value == 3) {
title = "售后"
}
// 将获取到数据塞到本页面用来控制tabs的数组里面
arrList.value.forEach(i => {
i.name = title
i.type = active.value
})
})
</script>
<style lang="less" scoped>
.my-order-list {
width: 100%;
height: 100%;
.head-box {
width: 100%;
background: rgb(245, 245, 245);
}
.list-box {
margin: 0 10px;
min-height: calc(100vh - 96px - 70px);
.card {
margin: 20px 0 0 0;
}
}
}
</style>