乐意购项目前端开发 #4

一、Home页面组件结构

结构拆分

 创建组件

在 views/Home 目录下创建component 目录, 然后在该目录下创建5个组件: 左侧分类(HomeCategory.vue)、Banner(HomeBanner.vue)、精选商品(HomeHot.vue)、低价商品(Homecheap.vue)、最新上架(HomeNew.vue)

引用组件

修改 views/Home/index.vue 的代码

<template>
  <div class="container">
    <HomeCategory></HomeCategory>
    <HomeBanner></HomeBanner>
  </div>
  <HomeHot></HomeHot>
  <HomeCheap></HomeCheap>
  <HomeNew></HomeNew>
</template>

<script>
import HomeBanner from './component/HomeBanner.vue'
import HomeCategory from './component/HomeCategory.vue'
import HomeHot from './component/HomeHot.vue'
import HomeNew from './component/HomeNew.vue'
import HomeCheap from './component/HomeCheap'
export default {
  components:{
    HomeBanner,
    HomeCategory,
    HomeHot,
    HomeNew,
    HomeCheap
  }

}
</script>

<style>

</style>

二、安装Pinia

添加依赖

pinia依赖和持久化插件

npm install pinia
npm install pinia-plugin-persist

创建文件

在 stores 目录下创建 category.js 文件

import { ref } from 'vue'
import { defineStore } from 'pinia'

引入

修改 main.js 文件

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { createPinia } from 'pinia' 
import piniaPersist from 'pinia-plugin-persist'
import ElementPlus from 'element-plus'
import "@/assets/iconfont/iconfont.js"
import "@/assets/iconfont/iconfont.css"

// import './styles/element/index.scss'

const pinia = createPinia()
pinia.use(piniaPersist)
const app = createApp(App)

app.use(store).use(router).use(pinia).use(ElementPlus).mount('#app')

三、分类功能实现

封装接口

在 api 目录下创建 home 目录然后创建 category.js 文件

import http from '@/utils/http'

export function getCategoryAPI () {
  return http({
    url: '/home/category/list',
    method: 'get',
  })
}

前提: 后端要返回相应的数据

修改 /store/category.js

import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getCategoryAPI } from '@/api/home/category'

export const useCategoryStore = defineStore('category', () => {
    // 导航列表数据管理
    //state 导航列表数据
    const categoryList = ref([])

    // action 获取导航数据的方法
    const getCategory = async () => {
        const res = await getCategoryAPI();
        console.log(res);
        categoryList.value = res.data;
    }

    return {
        categoryList, getCategory
    }
})

代码示范

HomeCategory.vue

<script setup>
import { useCategoryStore } from '@/store/category'
const categoryStore = useCategoryStore()
console.log(categoryStore);
</script>

<template>
  <div class="home-category">
    <ul class="menu">
      <li v-for="item in categoryStore.categoryList" :key="item.id">
        <i :class=item.icon></i>
        <router-link to="/">{{ item.categoryName }}</router-link>
        <span class="more">
          <a href="/">></a>
        </span>
        <!-- 弹层layer位置 -->
        <!-- <div class="layer">
          <h4>分类推荐 <small>根据您的购买或浏览记录推荐</small></h4>
          <ul>
            <li v-for="i in 5" :key="i">
              <RouterLink to="/">
                <img alt="" />
                <div class="info">
                  <p class="name ellipsis-2">
                    男士外套
                  </p>
                  <p class="desc ellipsis">男士外套,冬季必选</p>
                  <p class="price"><i>¥</i>200.00</p>
                </div>
              </RouterLink>
            </li>
          </ul>
        </div> -->
      </li>
    </ul>
  </div>
</template>


<style scoped lang='scss'>
.home-category {
  width: 250px;
  height: 500px;
  background: #f2f2f2;
  position: relative;
  z-index: 99;

  .menu {
    li {
      padding-left: 40px;
      height: 55px;
      line-height: 55px;
      text-align: left;
      padding-right: 15px;

      border-bottom: solid .1px #000;
      .iconfont{
        font-size: 22px;
        line-height: 55px;
        margin-right: 10px;
        top: 5px;
        color: rgb(0, 110, 255);
      }
      &:hover {
        background: $lygColor;
      }

      a {
        position: absolute;
        margin-right: 4px;
        color: #000;

        &:first-child {
          font-size: 16px;
        }
      }
      .more{
        float: right;
        font-size: 18px;
      }

      .layer {
        width: 990px;
        height: 500px;
        background: rgba(255, 255, 255, 0.8);
        position: absolute;
        left: 250px;
        top: 0;
        display: none;
        padding: 0 15px;

        h4 {
          font-size: 20px;
          font-weight: normal;
          line-height: 80px;

          small {
            font-size: 16px;
            color: #666;
          }
        }

        ul {
          display: flex;
          flex-wrap: wrap;

          li {
            width: 310px;
            height: 120px;
            margin-right: 15px;
            margin-bottom: 15px;
            border: 1px solid #eee;
            border-radius: 4px;
            background: #fff;

            &:nth-child(3n) {
              margin-right: 0;
            }

            a {
              display: flex;
              width: 100%;
              height: 100%;
              align-items: center;
              padding: 10px;

              &:hover {
                background: #e3f9f4;
              }

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

              .info {
                padding-left: 10px;
                line-height: 24px;
                overflow: hidden;

                .name {
                  font-size: 16px;
                  color: #666;
                }

                .desc {
                  color: #999;
                }

                .price {
                  font-size: 22px;
                  color: $priceColor;

                  i {
                    font-size: 16px;
                  }
                }
              }
            }
          }
        }
      }

      // 关键样式  hover状态下的layer盒子变成block
      &:hover {
        .layer {
          display: block;
        }
      }
    }
  }
}
</style>

四、banner功能实现

接口封装

 在 api 目录下创建 home 目录然后创建 banner.js 文件

import http from '@/utils/http'

export function getBannerAPI () {
  return http({
    url: '/home/banner/list',
    method: 'get',
  })
}

代码示范

HomeBanner.vue

<script setup>
import { getBannerAPI } from '@/api/home/banner'
import { onMounted, ref } from 'vue'

const bannerList = ref([])

const getBanner = async () => {
  const res = await getBannerAPI()
  console.log(res)
  bannerList.value = res.data
}

onMounted(() => getBanner());
console.log(bannerList)
</script>

<template>
  <div class="home-banner">
    <el-carousel height="500px">
      <el-carousel-item v-for="item in bannerList" :key="item.id">
        <img :src="require(`@/assets/img/${item.img1}.jpg`)" alt="">
      </el-carousel-item>
    </el-carousel>
  </div>
</template>




<style scoped lang='scss'>
.home-banner {
  width: 1127px;
  height: 500px;
  position: absolute;
  left: 250px;
  top: 185px;
  z-index: 98;

  img {
    width: 100%;
    height: 500px;
  }
}
</style>

五、创建公共组件

创建文件

在 views/Home/components 路径下创建 HomePanel.vue 文件

<script setup>
//定义 Props,主标题和副标题
defineProps({
    title: {
        type: String
    },
    subTitle: {
        type: String
    }
})
</script>


<template>
  <div class="home-panel">
    <div class="container">
  <div class="head">
    <!-- 主标题和副标题 -->
    <h3>
      {{title}}<small>{{ subTitle }}</small>
    </h3>
  </div>
  <!-- 主体内容区域 插槽-->
  <slot/>
</div>

  </div>
</template>

<style scoped lang='scss'>
.home-panel {
  background-color: #fff;

  .head {
    padding: 40px 0;
    display: flex;
    align-items: flex-end;

    h3 {
      flex: 1;
      font-size: 32px;
      font-weight: normal;
      margin-left: 6px;
      height: 35px;
      line-height: 35px;

      small {
        font-size: 16px;
        color: #999;
        margin-left: 20px;
      }
    }
  }
}
</style>

六、精选商品实现

 接口封装

 在 api 目录下创建 home 目录然后创建 hot.js 文件

代码示范

HomeHot.vue

<script setup>
import HomePanel from './HomePanel.vue';
import { ref, onMounted } from 'vue'
import { getHotAPI } from '@/api/home/hot'

const hotList = ref([])
const getHotList = async() => {
    const res = await getHotAPI()
    console.log(res)
    hotList.value = res.data
}

onMounted(() => {
    getHotList()
})
</script>

<template>
    <HomePanel title="精选商品" sub-title="人气精选 不容错过">
        <!-- 下面是插槽主体内容模版 -->
        <ul class="goods-list">
            <li v-for="item in hotList" :key="item.id">
                <RouterLink to="/">
                    <img :src="require(`@/assets/img/${item.picture1}.jpg`)" :alt="item.alt" />
                    <p class="name">{{ item.goodsName }}</p>
                    <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
            </li>
        </ul>
    </HomePanel>
</template>


<style scoped lang='scss'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  width: 100%;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

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

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      color: #000;
    }

    .price {
      color: $priceColor;
    }
  }
}
</style>

七、低价好物

 接口封装

 在 api 目录下创建 home 目录然后创建 cheap.js 文件

代码示范

HomeCheap.vue

<script setup>
import HomePanel from './HomePanel.vue';
import { ref, onMounted } from 'vue'
import { getCheapAPI } from '@/api/home/cheap'

const cheapList = ref([])
const getCheapList = async() => {
    const res = await getCheapAPI()
    console.log(res)
    cheapList.value = res.data
}

onMounted(() => {
    getCheapList()
})
</script>

<template>
    <HomePanel title="低价好物" sub-title="价低质不低 不容错过">
        <!-- 下面是插槽主体内容模版 -->
        <ul class="goods-list">
            <li v-for="item in cheapList" :key="item.id">
                <RouterLink to="/">
                    <img :src="require(`@/assets/img/${item.picture1}.jpg`)" :alt="item.alt" />
                    <p class="name">{{ item.goodsName }}</p>
                    <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
            </li>
        </ul>
    </HomePanel>
</template>


<style scoped lang='scss'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  width: 100%;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

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

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      color: #000;
    }

    .price {
      color: $priceColor;
    }
  }
}
</style>

八、最新上架

 接口封装

 在 api 目录下创建 home 目录然后创建 new.js 文件

代码示范

HomeNew.vue

<script setup>
import HomePanel from './HomePanel.vue';
import { ref, onMounted } from 'vue'
import { getNewAPI } from '@/api/home/new'

const newList = ref([])
const getNewList = async() => {
    const res = await getNewAPI()
    console.log(res)
    newList.value = res.data
}

onMounted(() => {
    getNewList()
})
</script>

<template>
    <HomePanel title="最新上架" sub-title="新鲜出炉 品质保障">
        <!-- 下面是插槽主体内容模版 -->
        <ul class="goods-list">
            <li v-for="item in newList" :key="item.id">
                <RouterLink to="/">
                    <img :src="require(`@/assets/img/${item.picture1}.jpg`)" :alt="item.alt" />
                    <p class="name">{{ item.goodsName }}</p>
                    <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
            </li>
        </ul>
    </HomePanel>
</template>


<style scoped lang='scss'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  width: 100%;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

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

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      color: #000;
    }

    .price {
      color: $priceColor;
    }
  }
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/338806.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

5.2 内容管理模块 - 课程发布需求分析、分布式技术方案

内容管理模块 - 课程发布 - 分布式技术方案、 课程发布需求分析 文章目录 内容管理模块 - 课程发布 - 分布式技术方案、 课程发布需求分析一、分布式事务技术方案1.1 本地事务1.2 分布式事务1.3 CAP理论1.4 分布式事务控制方案 二、课程发布2.1 需求分析2.2 数据模型2.2.1 课程…

EasyRecovery2024专业免费的数据恢复软件,支持从硬盘、光盘、U盘、移动硬盘、等所有类型的介质上恢复数据。

Ontrack EasyRecovery Home是一款企业级的数据恢复软件&#xff0c;支持从硬盘、光盘、U盘、移动硬盘、硬件RAID及软件RAID等所有类型的介质上恢复数据。支持恢复误删除、磁盘格式化、磁盘重新分区、磁盘逻辑坏道等原因而丢失的数据。支持RAID重建&#xff01;Ontrack EasyReco…

python基础学习-01

Python 是一种简单易学并且结合了解释性、编译性、互动性和面向对象的脚本语言。Python提供了高级数据结构&#xff0c;它的语法和动态类型以及解释性使它成为广大开发者的首选编程语言。 Python 是解释型语言&#xff1a; 开发过程中没有了编译这个环节。类似于PHP和Perl语言。…

「环境配置」使用Windows自带工具清理C盘空间

​ Windows电脑操作系统一般是安装在磁盘驱动器的C盘中&#xff0c;一旦运行&#xff0c;便会产生许多垃圾文件&#xff0c;C盘空间在一定程度上都会越来越小。伴随着电脑工作的时间越久&#xff0c;C盘常常会提示显示其内存已不足。本文记录笔者清理机器的步骤。 一、使用Win…

学会这个工具,小白也可制作门窗电子画册

​随着互联网技术的发展&#xff0c;现在制作电子画册已经变得非常简单。如果你是一个新手&#xff0c;也可以通过学习一些技巧来制作门窗电子画册。 那么&#xff0c;如何制作门窗电子画册呢&#xff1f;其实&#xff0c;这个过程并不复杂。只需要一台电脑和一个基本的操作工具…

Flask 3.x log全域配置(包含pytest)

最近使用到flask3.x&#xff0c;配置了全域的log&#xff0c;这边记录下 首先需要创建logging的配置文件&#xff0c;我是放在项目根目录的&#xff0c; Logging 配置 logging.json {"version": 1, # 配置文件版本号"formatters": {"default&qu…

「优选算法刷题」:在排序数组中查找元素的第一个和最后个位置

一、题目 给你一个按照非递减顺序排列的整数数组 nums&#xff0c;和一个目标值 target。请你找出给定目标值在数组中的开始位置和结束位置。 如果数组中不存在目标值 target&#xff0c;返回 [-1, -1]。 你必须设计并实现时间复杂度为 O(log n) 的算法解决此问题。 示例 1&a…

C#调用Newtonsoft.Json将bool序列化为int

使用Newtonsoft.Json将数据对象序列化为Json字符串时&#xff0c;如果有布尔类型的属性值时&#xff0c;一般会将bool类型序列化为字符串&#xff0c;true值序列化为true&#xff0c;false值序列化为false。如下面的类型序列化后的结果如下&#xff1a; public class UserInfo…

LINUX文件fd(file descriptor)文件描述符

目录 1.文件接口 1.1open 1.2C语言为什么要对open进行封装 2.fd demo代码 第一个问题 第二个问题 打开文件流程 引言&#xff1a;在学习C语言的时候&#xff0c;我们见过很多的文件的接口&#xff0c;例如fopen&#xff0c;fwrite&#xff0c;fclose等等&#xff0c;但…

Linux上软件安装

软件安装常见方式 二进制发布包 软件已经针对具体平台编译打包发布&#xff0c;只要解压&#xff0c;修改配置即可。 RPM包 软件已经按照redhat的包管理工具规范RPM进行打包发布&#xff0c;需要获取到相应的软件RPM发布包&#xff0c;然后用RPM命令进行安装&#xff0c;但…

2024年高校建设大数据实验室建设的意义

数据挖掘与大数据分析是以计算机基础为基础&#xff0c;以挖掘算法为核心&#xff0c;紧密面向行业应用的一门综合性学科。其主要技术涉及概率论与数理统计、数据挖掘、算法与数据结构、计算机网络、并行计算等多个专业方向&#xff0c;因此该学科对于实验室具有较高的专业要求…

Vue—指令

文章目录 指令初识 和 v-htmlVue指令1.v-html&#xff08;动态解析标签&#xff09;2.v-show&#xff08;display&#xff09; VS v-if&#xff08;添加和删除&#xff09;3.v-else和v-else-if&#xff08;与v-if一起使用&#xff09;4.v-on①v-on两种用法②v-on调用传参 5.v-b…

如何通过frp、geoserver发布家里电脑的空间数据教程

如何通过家里电脑的geoserver发布空间数据的教程 简介 大家好&#xff0c;我是锐多宝&#xff0c;最近我在开发一个新网站的时候遇到一个需求&#xff0c;这里记录一下以帮助需要用到的网友。 我的需求是&#xff1a;用户通过网站前端上传空间数据后&#xff0c;即可在前端展…

用友-u9-patchfile-任意文件上传-未公开Day漏洞复现

0x01阅读须知 本文章仅供参考&#xff0c;此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等&#xff08;包括但不限于&#xff09;进行检测或维护参考。本文章仅用于信息安全防御技术分享&#xff0c;因用于其他用途而产生不良后果,作者不承担任何法律责任&#…

Kafka-消费者-KafkaConsumer分析-Heartbeat

在前面分析Rebalance操作的原理时介绍到&#xff0c;消费者定期向服务端的GroupCoordinator发送HeartbeatRequest来确定彼此在线。 下面就来详细分析KafkaConsumer中Heartbeat的相关实现。 首先了解一下心跳请求和响应的格式。HeartbeatRequest的消息体格式比较简单&#xff…

YOLOv8 更换主干网络之 HGNetV2

论文地址:https://arxiv.org/abs/2304.08069 代码地址:https://github.com/PaddlePaddle/PaddleDetection 中文翻译:https://blog.csdn.net/weixin_43694096/article/details/131353118 YOLOv8 更换方式 YOLOv8 想用这个主干直接换就行了,因为项目里面已经集成了,写一个…

class_14:继承

C继承有点类似于c语言 结构体套用 #include <iostream> #include <string> using namespace std;//基类,父类 class Vehicle{ public:string type;string contry;string color;double price;int numOfWheel;void run();void stop(); };//派生类&#xff0c…

检索增强(RAG)的方式---重排序re-ranking

提升RAG&#xff1a;选择最佳嵌入Embedding&重排序Reranker模型 检索增强生成(RAG)技术创新进展&#xff1a;自我检索、重排序、前瞻检索、系统2注意力、多模态RAG RAG的re-ranking指的是对初步检索出来的候选段落或者文章&#xff0c;通过重新排序的方式来提升检索质量。…

JavaScript 学习笔记(WEB APIs Day3)

「写在前面」 本文为 b 站黑马程序员 pink 老师 JavaScript 教程的学习笔记。本着自己学习、分享他人的态度&#xff0c;分享学习笔记&#xff0c;希望能对大家有所帮助。推荐先按顺序阅读往期内容&#xff1a; 1. JavaScript 学习笔记&#xff08;Day1&#xff09; 2. JavaSc…

IaC基础设施即代码:Terraform 进行 lifecycle 生命周期管理

目录 一、实验 1.环境 2.Terraform 创建网络资源 3.Terraform 进行 create_before_destroy&#xff08;销毁前创建新资源&#xff09; 4.Terraform 进行 prevent_destroy&#xff08;防止资源被销毁&#xff09; 5.Terraform 进行 ignore_changes&#xff08;忽略资源的差…
最新文章