vue3前端开发-小兔鲜项目-面包屑导航的渲染

vue3前端开发-小兔鲜项目-面包屑导航的渲染!今天来完成,一级分类页面顶部,面包屑导航的渲染。


1:完善好一级页面内的基础模块代码。

<script setup>
import {getCategoryAPI} from '@/apis/category'
import {ref,onMounted} from 'vue'
import {useRoute} from 'vue-router'
const categoryData = ref({})
const route = useRoute()
const getCagegoryData = async () =>{
    // 如何在setup中获取路由参数 useRoute() -> route 等价于this.$route
    const res = await getCategoryAPI(route.params.id)
    categoryData.value = res.result
}
onMounted(()=> getCagegoryData())
</script>
<template>
    <div class="top-category">
        <div class="container m-top-20">
            <!--面包屑导航-->
            <div class="bread-container">
                <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>{{ categoryData.name }}</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </div>
    </div>
    
</template>
<style scoped lang="scss">
.top-category {
  h3 {
    font-size: 28px;
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 100px;
  }

  .sub-list {
    margin-top: 20px;
    background-color: #fff;

    ul {
      display: flex;
      padding: 0 32px;
      flex-wrap: wrap;

      li {
        width: 168px;
        height: 160px;


        a {
          text-align: center;
          display: block;
          font-size: 16px;

          img {
            width: 100px;
            height: 100px;
          }

          p {
            line-height: 40px;
          }

          &:hover {
            color: $xtxColor;
          }
        }
      }
    }
  }

  .ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;

    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }

      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }

    .body {
      display: flex;
      justify-content: space-around;
      padding: 0 40px 30px;
    }
  }

  .bread-container {
    padding: 25px 0;
  }
}
</style>

2:准备好接口调用的代码。

//这个名字可以自己定义的,这里定义成了request,是为了写起来简洁
import request from '@/utils/http'

export  function getCategoryAPI(id){
    return request({
        url:'/category',
        params:{id}

    })
}

 代码里可以看见,我们这个自定义函数,是带参数的。id参数,是一级栏目的id。它可以从路由参数对象useRoute的实体类对象中获取到。 


如图,从首页顶部导航点击一级分类,就进入了一级分类页面,面包屑导航跟着也刷新了。 

而且我们确实拿到了详细的数据。

如图,我们拿到了来自业务接口 返回的数据对象。里面包含了我们需要的数据信息。 

最近更新

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

    2024-07-20 17:16:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 17:16:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 17:16:03       45 阅读
  4. Python语言-面向对象

    2024-07-20 17:16:03       55 阅读

热门阅读

  1. windows 安装 kubectl 并连接到 k8s 集群【图文教程】

    2024-07-20 17:16:03       21 阅读
  2. computeIfAbsent 和 putIfAbsent

    2024-07-20 17:16:03       19 阅读
  3. 微软Edge浏览器全解析教程

    2024-07-20 17:16:03       18 阅读
  4. 如何使用unittest框架来编写和运行单元测试

    2024-07-20 17:16:03       20 阅读
  5. 数学建模熵权法

    2024-07-20 17:16:03       21 阅读
  6. RabbitMQ线程和连接模型详解

    2024-07-20 17:16:03       22 阅读
  7. 探索现代Web开发:WebKit的剪贴板API革新

    2024-07-20 17:16:03       26 阅读
  8. Node.js 路由

    2024-07-20 17:16:03       18 阅读