uniapp微信小程序自定义封装分段器。

uniapp微信小程序自定义封装分段器。

话不多说先上效果

这里我用的是cil框架 vue3 下面贴代码
组价代码:

typescript 复制代码
<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>

父组件使用方法:

typescript 复制代码
<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: "未进行",
    num: 5,
  },
  {
    title: "进行中",
    num: 2,
  },
  {
    title: "已完成",
    num: 12,
  },
]);
const changeNav = (index: number) => {
  console.log(index);
};
</script>
相关推荐
HackTwoHub10 分钟前
ARL灯塔重构版:支持APP/小程序/WEB资产同步扫描
人工智能·安全·web安全·网络安全·小程序·重构·自动化
投票竞赛3 小时前
避雷按单场活动扣费平台,2026 在线投票测评不限频次新建投票评选活动
小程序
2501_915909065 小时前
IPA 深度混淆是什么意思?从混淆强度到实际效果的解读
android·ios·小程序·https·uni-app·iphone·webview
莫名的好感°7 小时前
2026家庭快消品采购小程序实测体验
小程序
蜡台7 小时前
修改Uniapp input 组件不刷新视图问题
前端·uni-app·input
黄华SJ520it19 小时前
新零售排队免单系统开发全流程介绍
小程序·零售·系统开发
宸翰1 天前
uni-app 设置 Android 底部虚拟导航栏背景色
android·前端·uni-app
千逐681 天前
UniApp 鸿蒙实战:音视频与多媒体处理完全指南
华为·uni-app·harmonyos·鸿蒙
handsome09161 天前
windows开发uniapp如何上架app到app store
uni-app·上架
宠友信息1 天前
Redis 内容社区源码架构优化与即时通讯数据一致性处理
spring boot·后端·websocket·mysql·uni-app