uniapp Vue3 面包屑导航 带动态样式

上干货

 

<template>
  <view class="bei">
    <view class="container">
      <view class="indicator"></view>
      <!-- 遍历路由列表 -->
      <view v-for="(item, index) in routes" :key="index" :class="['foritem', {'selected': item.to === selectedRoute}]" @click="dianji(item)">
        <view class="item">
          {
  { item.name }}
        </view>
      </view>
    </view>
  </view>
  <view class="tip" v-if="selectedPage == 'A'">
    您已转到 {
  { selectedPage }} 页面
  </view>
  <view class="tip" v-if="selectedPage == 'B'">
    您已转到 {
  { selectedPage }} 页面
  </view>
  <view class="tip" v-if="selectedPage == 'C'">
    您已转到 {
  { selectedPage }} 页面
  </view>
</template>

<script setup>
  import { onMounted, ref } from "vue"

  // 定义路由列表
  const routes = ref([
    {
      to: "A",
      name: "A页面",
    },
    {
      to: "B",
      name: "B页面",
    },
    {
      to: "C",
      name: "C页面",
    },
  ])
  // 当前选中的路由
  const selectedRoute = ref("")
  // 当前选中的页面
  const selectedPage = ref("")


  // 点击路由项的处理函数
  function dianji(item) {
    console.log("点击", item.to)
    selectedRoute.value = item.to
    selectedPage.value = item.to
    const index = routes.value.findIndex(route => route.to === item.to)
  }

  // 组件挂载后的初始化
  onMounted(() => {
    selectedRoute.value = "A" // 将"A页面"设置为被点击状态
    selectedPage.value = "A" // 设置初始提示信息
  })
</script>

教学地址

点击跳转教学页面

完整源码下载地址

点击跳转下载页面

也可以添加下方的名片进行咨询

相关推荐

  1. C# EPPlus导出dataset----Excel3样式

    2023-12-28 20:14:03       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-28 20:14:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-28 20:14:03       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-28 20:14:03       82 阅读
  4. Python语言-面向对象

    2023-12-28 20:14:03       91 阅读

热门阅读

  1. css吸顶(position: sticky;)

    2023-12-28 20:14:03       90 阅读
  2. 【排序算法】合并两个有序数组

    2023-12-28 20:14:03       58 阅读
  3. MongoDB

    MongoDB

    2023-12-28 20:14:03      56 阅读
  4. Tekton

    Tekton

    2023-12-28 20:14:03      51 阅读
  5. MongoDB中的物化视图

    2023-12-28 20:14:03       58 阅读
  6. 2022年全国职业院校技能大赛软件测试赛项赛题库

    2023-12-28 20:14:03       55 阅读
  7. Linux安装mysql

    2023-12-28 20:14:03       60 阅读
  8. 全国计算机等级考试| 二级Python | 真题及解析(1)

    2023-12-28 20:14:03       49 阅读
  9. 机器学习概述(一)

    2023-12-28 20:14:03       36 阅读
  10. 备忘录模式(Memento)

    2023-12-28 20:14:03       60 阅读