前端进阶之路-从传统前端到VUE-JS(第五期-路由应用)

在之前的学习中我们知道我们可以用router文件夹里的index.ts来调整路由那么我们本期内容便是如此,通过路由调整来实现网页跳转

(路由真的是一个很抽象的东西,至少在我学习的过程中觉得很麻烦的,所以,如果长时间理解不了就直接看其它的内容就行,慢慢的就了解路由了)

在此之前,我们还需要通过看Element plus官方文档来了解怎么实现点击对应按钮来实现相应动作

https://element-plus.org/zh-CN/component/menu.html#菜单-api

由此,我们再来修改一下(NavigationBar.vue文件中修改)

复制代码
<template>

  <el-menu

    :default-active="activeIndex"

    class="el-menu-demo"

    mode="horizontal"

    @select="handleSelect"

  >

    <el-menu-item index="1">你好</el-menu-item>

    <el-sub-menu index="2">

      <template #title>工作区</template>

      <el-menu-item index="2-1">item one</el-menu-item>

      <el-menu-item index="2-2">item two</el-menu-item>

      <el-menu-item index="2-3" @click="MenuClick">测试</el-menu-item>

      <el-sub-menu index="2-4">

        <template #title>测试1</template>

        <el-menu-item index="2-4-1">测试2</el-menu-item>

        <el-menu-item index="2-4-2">item two</el-menu-item>

        <el-menu-item index="2-4-3">item three</el-menu-item>

      </el-sub-menu>

    </el-sub-menu>

    <el-menu-item index="3" disabled>Info</el-menu-item>

    <el-menu-item index="4">Orders</el-menu-item>

  </el-menu>

  <div class="h-6" />

</template>

<style scoped></style>

<script setup lang="ts">

import { ref } from "vue";

import { useRouter } from "vue-router";

interface MenuItemRegistered {

  index: string;

  title: string;

}

const activeIndex = ref("1");

const router = useRouter();

const handleSelect = (key: string) => {

  router.push({

    path: key,

  });

};

const MenuClick = (item: MenuItemRegistered) => {

  console.log(item);

};

</script>

之前

之后

我们在上面的内容中,我们给每个页面制定了url,不会出现之前点击导航栏的内容但是url不变的情况,这就是基本的路由利用

至此,前端vue框架的内容就暂时告一段落,但是并没有结束,因为涉及到后端的内容,我觉得了解后端学习后可以更好的了解路由以及vue的特点和使用方式,对于有后端基础的朋友,如果有问题请继续研究官方文档或等之后的内容

相关推荐
kyriewen7 小时前
我手写了一个 EventEmitter,面试官追问了 6 个问题——第 4 个我没答上来
前端·javascript·面试
IT_陈寒7 小时前
Java的Date类又坑了我一次,改用时间戳真香
前端·人工智能·后端
山河木马8 小时前
矩阵专题2-怎么创建视图矩阵(uViewMatrix)
javascript·webgl·计算机图形学
小林攻城狮8 小时前
使用 Transport 节流解决 Vercel AI SDK 流式渲染卡死问题
前端·react.js
前端缘梦8 小时前
告别 TS 运行时类型漏洞!Zod 完整入门实战教程(前端 / 全栈必备)
前端·react.js·全栈
the_answer9 小时前
Webpack vs Vite 深度对比分析
前端·webpack
转转技术团队9 小时前
验证码识别实战:前端不写页面,改训模型了?
前端
MomentYY9 小时前
Temperature:AI 的“脑洞旋钮”
前端·llm·ai编程
远航_9 小时前
OpenSpec 完整详细介绍
前端·后端
召钱熏9 小时前
状态枚举正确≠渲染正确:一个语音按钮的状态机边界修复实录
android·前端