路由循环 自定义样式 和跳转 vue3

<template>
  <div>
    <div class="row">
      <div class="ymdiv" v-for="(item, index) in menuList1" :key="index">
        <div class="fName" v-if="hasChild(item)">{{ item.name }}</div>
        <div class="fName" @click="gnClick(item, index)" v-else>{{ item.name }}</div>
        <div class="rowChild">
          <div class="ChildDiv" v-for="(item1, index1) in item.children" :key="index1">
            <div class="cName" v-if="hasChild(item1)">
              <div class="dd">{{ item1.name }}</div>
              <div class="bb">
                <div v-for="(item2, index2) in item1.children" :key="index2" @click="gnClick(item2, index2)">{{
                    item2.name
                }}</div>
              </div>
            </div>
            <div class="cName aa" @click="gnClick(item1, index1)" v-else>{{ item1.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { initMenu } from "@/utils/menu-api.js";
const router = useRouter();
const menuList1 =  ref([]);
initMenu().then(res=>{
  menuList1.value = res;
})
//菜单数据
function hasChild(item) {
  return item && item.children && item.children.length > 0;
}
function gnClick(item) {
  console.log(item)
  router.push({
    path: item.path
  });
}
</script>

<style scoped>
.row {
  display: flex;
  margin-bottom: 5px;
  margin-left: 35px;
  flex-wrap: wrap;
}

.aa {
  line-height: 150px;
}

.rowChild {
  display: flex;
  margin-bottom: 5px;
  flex-wrap: wrap;
  margin-left: 70px;
}

.bb {
  display: flex;
  justify-content: space-around;
  margin-top: 40px;
}

.ChildDiv {
  width: 150px;
  height: 150px;
  /* line-height: 150px; */
  margin: 10px;
  text-align: center;
  cursor: pointer;
  border-radius: 10px;
  /* border: 1px solid #ccc; */
  box-shadow: -2px 2px 2px 2px #d2d4d4;
}

.ymdiv {
  overflow-y: scroll;
  overflow-x: hidden;
  width: 500px;
  height: 500px;
  margin: 10px;
  text-align: center;
  border-radius: 10px;
  box-shadow: -2px 2px 5px 2px #c5c5c5;
}

/* 整个滚动条 */
::-webkit-scrollbar {
  width: 3px;
  height: 3px;
  border-radius: 50%;
}

/* 滚动条有滑块的轨道部分 */
::-webkit-scrollbar-track-piece {
  background-color: transparent;
  border-radius: 10px;
}

/* 滚动条滑块(竖向:vertical 横向:horizontal) */
::-webkit-scrollbar-thumb {
  cursor: pointer;
  background-color: #b8b9b9;
  border-radius: 10px;
}

/* 滚动条滑块hover */
::-webkit-scrollbar-thumb:hover {
  background-color: #999999;
}

/* 同时有垂直和水平滚动条时交汇的部分 */
::-webkit-scrollbar-corner {
  display: block;
  /* 修复交汇时出现的白块 */
}

.fName {
  font-size: 20px;
  width: 500px;
  height: 50px;
  line-height: 50px;
  font-weight: bold;
  text-align: center;
  background-color: rgb(107, 170, 230);
}

.cName {
  font-size: 16px;
  text-align: center;
}
</style>

效果图
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值