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>
相关推荐
破无差7 小时前
《赛事报名系统小程序》
小程序·html·uniapp
00后程序员张8 小时前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬9 小时前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106329 小时前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
xkxnq9 小时前
Uniapp崩溃监控体系构建:内存泄漏三维定位法(堆栈/资源/线程)
uni-app
Qlittleboy9 小时前
uniapp如何使用本身的字体图标
javascript·vue.js·uni-app
写代码的jiang10 小时前
打造精简高效的 uni-app 网络请求工具
uni-app
亮子AI10 小时前
【小程序】微信小程序隐私协议
微信小程序·小程序
weixin_1772972206911 小时前
短剧小程序系统开发:打造个性化娱乐新平台
小程序·娱乐·短剧
weixin_lynhgworld11 小时前
剧本杀小程序系统开发:开启沉浸式社交娱乐新纪元
小程序·娱乐