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>
相关推荐
文心快码BaiduComate15 小时前
用Comate Zulu开发一款微信小程序
前端·后端·微信小程序
CHB18 小时前
uni-ai:让你的App快速接入AI
uni-app·deepseek
小徐_23333 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
iOS阿玮3 天前
永远不要站在用户的对立面,挑战大众的公知。
uni-app·app·apple
xw53 天前
uni-app中v-if使用”异常”
前端·uni-app
!win !3 天前
uni-app中v-if使用”异常”
前端·uni-app
Emma歌小白3 天前
如何首次运行小程序后端
微信小程序
赣州云智科技的技术铺子3 天前
【一步步开发AI运动APP】十二、自定义扩展新运动项目1
微信小程序·小程序·云开发·智能小程序
2501_915918413 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张3 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview