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

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

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

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

<template>
  <div class="cinema-search-filter-component">
    <nut-menu>
      <template #icon>
        <TriangleDown size="12" />
      </template>
      <nut-menu-item
        v-model="searchFilter.regionValue"
        :title="currentRegionTitle"
        :options="searchFilter.region"
      />
      <nut-menu-item
        v-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>

基本上就是这样的

相关推荐

  1. 封装搜索组件

    2024-04-02 06:08:04       8 阅读
  2. Vue项目axios封装

    2024-04-02 06:08:04       41 阅读
  3. nuxt.js使用axios以及封装

    2024-04-02 06:08:04       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-02 06:08:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-02 06:08:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-02 06:08:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-02 06:08:04       18 阅读

热门阅读

  1. 【Kotlin】匿名类和伴生类

    2024-04-02 06:08:04       16 阅读
  2. 基于mqtt的物联网控制移动应用程序开发

    2024-04-02 06:08:04       14 阅读
  3. Android RecycleView 缓存 itemView 提高滑动流畅度

    2024-04-02 06:08:04       13 阅读
  4. 做题目

    2024-04-02 06:08:04       15 阅读
  5. Android BLE蓝牙扫描系统源码解析学习笔记

    2024-04-02 06:08:04       14 阅读
  6. 关于ffmpeg的安装和编码格式问题

    2024-04-02 06:08:04       12 阅读
  7. Mongodb中一个小巧的数据更新命令$inc

    2024-04-02 06:08:04       12 阅读
  8. hcip-datacom英文词汇积累简述2

    2024-04-02 06:08:04       15 阅读
  9. 12、Lua 迭代器

    2024-04-02 06:08:04       15 阅读
  10. ubuntu 修改IP

    2024-04-02 06:08:04       14 阅读
  11. 算法2.6基数排序

    2024-04-02 06:08:04       10 阅读
  12. IDEA 在 Windows 系统上常用的快捷键

    2024-04-02 06:08:04       15 阅读