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>
相关推荐
StarChainTech11 小时前
电动车租赁中的智能管理:电子围栏技术如何改变出行行业
大数据·人工智能·微信小程序·小程序·团队开发·软件需求·共享经济
2503_9284115614 小时前
12.26 小程序问题和解决
前端·javascript·微信小程序·小程序
iOS阿玮17 小时前
鸿蒙激励的羊毛,你"薅"到了么?
uni-app·app·apple
qq_124987075318 小时前
基于springboot的智能任务管理助手小程序设计与实现(源码+论文+部署+安装)
spring boot·后端·信息可视化·微信小程序·小程序·毕业设计·计算机毕业设计
ResponseState20019 小时前
安卓原生写uniapp插件手把手教学调试、打包、发布。
前端·uni-app
菩提小狗21 小时前
第3天:基础入门-抓包&封包&协议&APP&小程序&PC应用&WEB应用|小迪安全笔记|网络安全|
前端·安全·小程序
百锦再21 小时前
万字解析:抖音小程序与微信小程序开发全景对比与战略选择
人工智能·ai·语言模型·微信小程序·小程序·模拟·模型
游九尘21 小时前
微信小程序根据设计稿适配
微信小程序
invicinble21 小时前
分析家教小程序的功能设计
小程序
h_65432101 天前
uniapp app端解析图片的经纬度、方位角
uni-app