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

相关推荐
sulikey3 分钟前
个人Linux操作系统学习笔记11 - 环境变量
linux·笔记·学习
吃糖的小孩44 分钟前
从只读页面到可控真实探针:我如何给 Owner Console 加手动诊断
前端
谷无姜1 小时前
为什么你的性能优化无效?可能是"木桶效应"在作祟
前端·性能优化
治愈系贝壳1 小时前
ARM --- day 6 时钟
linux·arm开发·学习
雾非雾1 小时前
《基于具身交互智能数字人技术:如何打造AI数字人宣讲平台"红厅智播”》
前端
Revolution611 小时前
一段 JavaScript 代码执行时,到底发生了什么
前端·javascript
智能起源1 小时前
关于元素层级过多,导致压祯的问题(使用winform或者WPF应用的webview组件嵌套网页时,动效卡顿问题)
前端
minglie11 小时前
zynq高频小数据量PS闭环的三个实验-第0课:目的和目标
学习
Old Uncle Tom2 小时前
银行用户画像 -- 金融目标与需求意图
前端·人工智能·金融