前端进阶之路-从传统前端到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的特点和使用方式,对于有后端基础的朋友,如果有问题请继续研究官方文档或等之后的内容

相关推荐
崔庆才丨静觅3 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby60614 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了4 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅4 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
执笔论英雄4 小时前
【大模型学习cuda】入们第一个例子-向量和
学习
wdfk_prog5 小时前
[Linux]学习笔记系列 -- [drivers][input]input
linux·笔记·学习
崔庆才丨静觅5 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
崔庆才丨静觅5 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment5 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
崔庆才丨静觅5 小时前
刷屏全网的“nano-banana”API接入指南!0.1元/张量产高清创意图,开发者必藏
前端