当前位置: 首页 > news >正文

nut-ui中的menu 菜单组件的二次封装

这个菜单组件 一般可以直接用到项目里 如果复用性不强的话 直接使用

但是有一个问题 如果很多地方都需要用到这个组件

我们可以把这个组件二次封装一下

<template><div class="cinema-search-filter-component"><nut-menu><template #icon><TriangleDown size="12" /></template><nut-menu-itemv-model="searchFilter.regionValue":title="currentRegionTitle":options="searchFilter.region"/><nut-menu-itemv-model="searchFilter.brandValue":title="currentBrandTitle":options="searchFilter.brand"/></nut-menu></div>
</template>
<script setup lang="ts">
import { ref, reactive, computed, onMounted, watch } from "vue";
import { useLocationStore } from "../../store";
import { TriangleDown } from "@nutui/icons-vue-taro";
const locationStore = useLocationStore();
let searchFilter = ref({region: [{ text: "全部", title: "全城", value: 0 }],brand: [{ text: "全部", title: "品牌", value: 0 }],regionValue: 0,brandValue: 0,
});
onMounted(() => {getRegionData();
});
const emit = defineEmits(["onRegionChanged", "onBrandChanged"]);
watch(() => searchFilter.value.regionValue,(newVal) => {emit("onRegionChanged", newVal);}
);
watch(() => searchFilter.value.brandValue,(newVal) => {emit("onBrandChanged", newVal);}
);
watch(() => locationStore.selectCityinfo,(newVal) => {getRegionData();}
);
const currentRegionTitle = computed(() => {const arr = searchFilter.value.region;const value = searchFilter.value.regionValue;return arr.find((item) => {return item.value === value;})?.title;
});
const currentBrandTitle = computed(() => {const arr = searchFilter.value.brand;const value = searchFilter.value.brandValue;return arr.find((item) => {return item.value === value;})?.title;
});
const getRegionData = async () => {initData();// const cityId = locationStore.selectCityinfo.cityId;// const res: any = await cityApi.region(cityId);// const arr = searchFilter.value.region;// res.forEach((item) => {//   arr.push({//     text: item.regionname,//     title: item.regionname,//     value: item.regionid,//   });// });// searchFilter.value.region = arr;
};
const initData = () => {searchFilter.value = {region: [{ text: "全部", title: "全城", value: 0 }],brand: [{ text: "全部", title: "品牌", value: 0 }],regionValue: 0,brandValue: 0,};
};
</script>
<style lang="scss">
.cinema-search-filter-component {display: flex;flex-direction: column;//   background: #fff;.nut-menu .nut-menu__bar {box-shadow: none !important;}.nut-menu__title-text {font-size: 24px;}.nut-menu__bar {background: none !important;}
}
</style>

基本上就是这样的

http://www.lryc.cn/news/331854.html

相关文章:

  • python笔记(11)序列
  • Rust egui(4) 增加自己的tab页面
  • 小组分享第二部分:Jsoup
  • C#(winform) 调用MATLAB函数
  • Kubernetes探索-Pod面试(补充)
  • 深入了解JUnit 5:新一代Java单元测试框架
  • 2024年清明节安装matlab 2024a
  • 关于PostgreSQL JDBC中的log输出是怎么回事?
  • 【科研笔记】知识星球不可选择内容爬虫
  • [技术闲聊]我对电路设计的理解(二)
  • 【Android、 kotlin】kotlin学习笔记
  • Debian 配置国内软件源
  • 选数(dfs,isprime)
  • RocketMQ(版本4.9.4)+RocketMQ_Dashbord环境搭建(生产者、消费者的前置环境搭建)
  • css隐藏溢出隐藏的滚动条
  • scss常用混入(mixin)、@inclue
  • 补代码随想录算法训练营第44天 | 完全背包、518. 零钱兑换 II 、377. 组合总和 Ⅳ
  • 【Linux】网络基础常识{OSI七层模型/ TCP/IP / 端口号 /各种协议}
  • python--面向对象编程和类的定义,对象的创建
  • nssm 工具把asp.net core mvc变成 windows服务,使用nginx反向代理访问
  • String Encryptor custom Bean not found with name ‘jasyptStringEncryptor‘...
  • FastAPI+React全栈开发14 FastAPI如何开发REST接口
  • 在 DDD 中,如何处理领域对象的持久化?
  • centos 如何安装nvidia-container-runtime
  • 非写代码无以致远
  • 刷题之Leetcode34题(超级详细)
  • 从0到1构建uniapp应用-store状态管理
  • Uinx线程详解
  • 线性代数笔记23--马尔可夫矩阵、傅里叶级数
  • Elasticsearch 压测实践总结