home.vue

<template>
  <!-- <div :search="search"> -->
  <div>    
    <v-app-bar app flat >
      <v-app-bar-nav-icon @click="drawer = !drawer"></v-app-bar-nav-icon>

      <v-toolbar-title>毕业设计</v-toolbar-title>

      <v-spacer></v-spacer>
      <!-- <v-text-field
        v-model="search"
        append-icon="mdi-magnify"
        label="Search"
        single-line
        hide-details
      ></v-text-field> -->

      <v-menu left bottom>
        <template v-slot:activator="{ on, attrs }">
          <v-btn icon v-bind="attrs" v-on="on">
            <v-icon>mdi-dots-vertical</v-icon>
          </v-btn>
        </template>

        <v-list>
          <v-list-item
            v-for="(item, index) in items"
            :key="index"
            router
            :to="item.route"
          >
            <v-list-item-title>{{ item.title }}</v-list-item-title>
          </v-list-item>
        </v-list>
      </v-menu>
    </v-app-bar>

    <v-navigation-drawer
      color="#AAAAA3"
      width="180px"
      v-model="drawer"
      app
      hide-overlay
      stateless
    >

    
      <v-list-item >
        <v-avatar >
          <img src="https://cdn.vuetifyjs.com/images/john.jpg" alt="John" />
        </v-avatar>
        <v-list-item-content style="text-align: center">
          <v-list-item-title class="title"> 某某 </v-list-item-title>
          <v-list-item-subtitle> DaiJuan </v-list-item-subtitle>
        </v-list-item-content>
      </v-list-item>

      <v-divider></v-divider>

      <v-list>
        <v-list-item
          v-for="(item, index) in items"
          :key="index"
          router
          :to="item.route"
          v-on:mouseover="showToggle(index)"
          v-on:mouseout="handleHide"
        >
          <v-list-item-icon>
            <v-icon>{{ item.icon }}</v-icon>
          </v-list-item-icon>
          <v-list-item-content>
            <v-list-item-title>
              {{ item.title }}
            </v-list-item-title>
          </v-list-item-content>
        </v-list-item>
      </v-list>
    </v-navigation-drawer>

    <v-content>
      <router-view></router-view>
    </v-content>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Home",
  components: {},
  data() {
    return {
      drawer: true,
      // search: '',
      items: [
        {
          title: "基本信息",
          icon: "mdi-account-box",
          route: "/Home/Profile",
        },
        {
          title: "学术论文",
          icon: "mdi-paperclip",
          route: "/Home/Research",
        },
        { title: "软件著作权", icon: "mdi-keyboard", route: "/Home/Copyright" },
        { title: "量子模拟", icon: "mdi-apple-airplay", route: "/Home/Simulate" },        
        { title: "校园经历", icon: "mdi-home", route: "/Home/College" },
        { title: "实战经历", icon: "mdi-gavel", route: "/Home/Project" },
      ],
    };
  },
  mounted: function () {
    // 避免第一个渲染的显示
    this.isShow = -1;
  },
  methods: {
    showToggle: function (index) {
      this.isShow = index;
    },
    handleHide: function () {
      this.isShow = !this.isShow;
    },
  },
};
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个非常不错的自动化路由生成的方法,使用 `require.context` 可以快速地遍历 views 文件夹下的所有 .vue 文件。下面是一个示例代码: ```javascript import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) // 生成路由配置 function generateRoutes(routeContext) { const routes = [] // 遍历所有 .vue 文件 routeContext.keys().forEach(key => { // 获取文件相对路径,如 './User.vue' const routePath = key.replace(/^\.\/(.*)\.\w+$/, '$1') // 根据文件路径生成路由配置 const routeConfig = { path: `/${routePath}`, name: routePath, component: () => import(`@/views/${routePath}.vue`) } // 判断是否是一级路由 if (routePath === 'Login' || routePath === 'Home') { routes.push(routeConfig) } else { const [parentPath, childPath] = routePath.split('/') let parentRoute = routes.find(route => route.path === `/${parentPath}`) if (!parentRoute) { parentRoute = { path: `/${parentPath}`, component: () => import(`@/views/${parentPath}/index.vue`), children: [] } routes.push(parentRoute) } parentRoute.children.push(routeConfig) } }) return routes } // 使用 require.context 生成路由配置 const routeContext = require.context('@/views', true, /\.vue$/) const routes = generateRoutes(routeContext) // 创建路由实例 const router = new Router({ mode: 'history', routes }) export default router ``` 在上面的代码中,我们首先定义了 `generateRoutes` 函数,它接受一个 `require.context` 对象作为参数,遍历所有 .vue 文件,根据文件路径生成路由配置。根据要求,Login.vueHome.vue 固定在 views 下作为一级路由,其他和 Login.vue 同一目录下的 vue 文件也是一级路由,其他文件夹下的 vue 文件以 index.vue 作为出口,且文件夹下的 index.vue 均在 Home.vue 的 children 下,其他文件夹下的除 index.vue 文件的路由均在 index.vue 的 children 下。 然后,我们使用 `require.context` 生成路由配置,并调用 `generateRoutes` 函数生成路由配置数组。最后,我们使用 `new Router` 创建路由实例,并将路由配置数组作为参数传入。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值