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>
相关推荐
汤姆yu4 小时前
基于微信小程序的学校招生系统
微信小程序·小程序·招生小程序
雪芽蓝域zzs4 小时前
uniapp 国密sm2加密
uni-app
说私域11 小时前
基于开源AI智能名片链动2+1模式的S2B2C商城小程序:门店私域流量与视频号直播融合的生态创新研究
人工智能·小程序·开源
说私域13 小时前
传统微商困境与开源链动2+1模式、AI智能名片及S2B2C商城小程序的转型破局
人工智能·小程序·开源
一渊之隔13 小时前
微信小程序在用户拒绝授权后无法使用wx.opensetting再次获取定位授权
微信小程序·小程序
打不着的大喇叭14 小时前
uniapp的光标跟随和打字机效果
前端·javascript·uni-app
zengzehui14 小时前
uniapp启动图被拉伸问题
uni-app
iOS阿玮17 小时前
AppStore教你一招免备案的骚操作!
uni-app·app·apple
racerun17 小时前
微信小程序如何实现再多个页面共享数据
微信小程序·小程序
XM-545817 小时前
2025微信小程序wxapkg解包全攻略
linux·运维·小程序