uniapp微信小程序自定義封裝分段器。
話不多說先上效果
這里我用的是cil框架 vue3 下面貼代碼
組價(jià)代碼:文章來源:http://www.zghlxwxcb.cn/news/detail-759217.html
<template>
<view class="page">
<view
v-for="(item, index) in navList"
:key="index"
@click="changeNav(index)"
:class="current == index ? 'selectNav' : ''"
>{{ item.title }}{{ item.num ? "(" + item.num + ")" : "" }}</view
>
</view>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
const emit = defineEmits(["changeNav"]);
const props = withDefaults(
defineProps<{
navList: any;
currentNav?: number;
}>(),
{ navList: [], currentNav: 0 }
);
const current = ref<number>(props.currentNav);
const changeNav = (index: number) => {
current.value = index;
emit("changeNav", current.value);
};
</script>
<style lang="scss" scoped>
.page {
width: 100%;
height: 88rpx;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-around;
font-size: 30rpx;
color: #14131f;
}
.selectNav {
color: #00cd73;
font-size: 34rpx;
position: relative;
font-weight: 600;
}
.selectNav::after {
content: "";
position: absolute;
bottom: -20rpx;
left: 0%;
width: 90rpx;
height: 10rpx;
background: #00cd73;
border-radius: 5rpx;
}
</style>
父組件使用方法:文章來源地址http://www.zghlxwxcb.cn/news/detail-759217.html
<template>
<view class="page">
<Sectionalizer :navList="navList" @changeNav="changeNav"></Sectionalizer>
</view>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import Sectionalizer from "@/components/sectionalizer.vue";
const navList = ref<any>([
{
title: "未進(jìn)行",
num: 5,
},
{
title: "進(jìn)行中",
num: 2,
},
{
title: "已完成",
num: 12,
},
]);
const changeNav = (index: number) => {
console.log(index);
};
</script>
到了這里,關(guān)于uniapp微信小程序自定義封裝分段器。的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!