vue3 之 商城项目—layout静态模版结构搭建

layout—模块静态模版搭建

一般情况下我们会有nav区域,header区域,二级路由出口区域以及footer区域,如图
在这里插入图片描述
我们在开发的时候先把大模块搭建起来,再一步一步填充小模块

在layout下建文件,目录如下
在这里插入图片描述

在index.vue中把上面文件引入进来

<script setup>
import LayoutNav from './components/LayoutNav.vue'
import LayoutHeader from './components/LayoutHeader.vue'
import LayoutFooter from './components/LayoutFooter.vue'
</script><template><LayoutNav /><LayoutHeader /><RouterView /><LayoutFooter />
</template>
layout—字体图标引入

阿里的字体图标库支持多种引入方式,项目里采用的是font-class引用的方式
index.html

  <link rel="stylesheet" href="//at.alicdn.com/t/font_2143783_iq6z4ey5vu.css">
layout— 一级导航渲染

在这里插入图片描述
apis/layout.js

//导入封装好的http请求 可以看上一章发布的内容项目起步
import httpInstance from "@/utils/http"
export function getCategoryAPI () {return httpInstance({url: '/home/category/head'})
}

layout/layoutHeader

<script setup>import { getCategoryAPI } from '@/apis/layout'import { onMounted, ref } from 'vue'const categoryList = ref([])const getCategory = async () => {const res = await getCategoryAPI()categoryList.value = res.result}onMounted(() => getCategory())</script><template><header class='app-header'><div class="container"><h1 class="logo"><RouterLink to="/">小兔鲜</RouterLink></h1><ul class="app-header-nav"><li class="home" v-for="item in categoryList" :key="item.id"><RouterLink to="/">{{ item.name }}</RouterLink></li></ul><div class="search"><i class="iconfont icon-search"></i><input type="text" placeholder="搜一搜"></div><!-- 头部购物车 --></div></header>
</template>
layout—吸顶导航交互实现

需求:浏览器在上下滚动的过程中,如果距离顶部的滚动距离大于78px,吸顶导航显示,小于78px隐藏
在这里插入图片描述
安装vueuse插件

npm i @vueuse/core
//用里面的useScorll来解决滚动问题

layout/components/layoutFixed.vue

<script setup>
import LayoutHeaderUl from './LayoutHeaderUl.vue'
// vueUse
import { useScroll } from '@vueuse/core'
const { y } = useScroll(window)
</script>
<template><div class="app-header-sticky" :class="{ show: y > 78 }"><div class="container"><RouterLink class="logo" to="/" /><!-- 导航区域 --><ul class="app-header-nav "><li class="home"><RouterLink to="/">首页</RouterLink></li><li><RouterLink to="/">居家</RouterLink></li><li><RouterLink to="/">美食</RouterLink></li><li><RouterLink to="/">服饰</RouterLink></li><li><RouterLink to="/">母婴</RouterLink></li><li><RouterLink to="/">个护</RouterLink></li><li><RouterLink to="/">严选</RouterLink></li><li><RouterLink to="/">数码</RouterLink></li><li><RouterLink to="/">运动</RouterLink></li><li><RouterLink to="/">杂项</RouterLink></li></ul><div class="right"><RouterLink to="/">品牌</RouterLink><RouterLink to="/">专题</RouterLink></div></div></div>
</template><style scoped lang='scss'>
.app-header-sticky {width: 100%;height: 80px;position: fixed;left: 0;top: 0;z-index: 999;background-color: #fff;border-bottom: 1px solid #e4e4e4;// 此处为关键样式!!!// 状态一:往上平移自身高度 + 完全透明transform: translateY(-100%);opacity: 0;// 状态二:移除平移 + 完全不透明&.show {transition: all 0.3s linear;transform: none;opacity: 1;}.container {display: flex;align-items: center;}.logo {width: 200px;height: 80px;background: url("@/assets/images/logo.png") no-repeat right 2px;background-size: 160px auto;}.right {width: 220px;display: flex;text-align: center;padding-left: 40px;border-left: 2px solid $xtxColor;a {width: 38px;margin-right: 40px;font-size: 16px;line-height: 1;&:hover {color: $xtxColor;}}}
}.app-header-nav {width: 820px;display: flex;padding-left: 40px;position: relative;z-index: 998;li {margin-right: 40px;width: 38px;text-align: center;a {font-size: 16px;line-height: 32px;height: 32px;display: inline-block;&:hover {color: $xtxColor;border-bottom: 1px solid $xtxColor;}}.active {color: $xtxColor;border-bottom: 1px solid $xtxColor;}}
}
</style>

layout/index.vue

//导入
import LayoutFixed from './components/LayoutFixed.vue'
layout— Pinia优化重复请求

项目中有两种导航,一种普通导航一种吸顶导航
在这里插入图片描述
在这里插入图片描述
stores/category.js

import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getCategoryAPI } from '@/apis/layout'
export const useCategoryStore = defineStore('category', () => {// 导航列表的数据管理// state 导航列表数据const categoryList = ref([])// action 获取导航数据的方法const getCategory = async () => {const res = await getCategoryAPI()categoryList.value = res.result}return {categoryList,getCategory}
})

layout/index.vue

// 触发获取导航列表的actionimport { useCategoryStore } from '@/stores/categoryStore'
import { onMounted } from 'vue'const categoryStore = useCategoryStore()onMounted(() => categoryStore.getCategory())

layout/components/layoutNav

// 触发获取导航列表的action
<script setup>
import { useCategoryStore } from '@/stores/categoryStore'
const categoryStore = useCategoryStore()
</script><template><ul class="app-header-nav"><li class="home"><RouterLink to="/">首页</RouterLink></li><li class="home" v-for="item in categoryStore.categoryList" :key="item.id"><RouterLink active-class="active" :to="`/category/${item.id}`">{{ item.name }}</RouterLink></li></ul>
</template><style lang="scss">
.app-header-nav {width: 820px;display: flex;padding-left: 40px;position: relative;z-index: 998;li {margin-right: 40px;width: 38px;text-align: center;a {font-size: 16px;line-height: 32px;height: 32px;display: inline-block;&:hover {color: $xtxColor;border-bottom: 1px solid $xtxColor;}}.active {color: $xtxColor;border-bottom: 1px solid $xtxColor;}}
}
</style>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于springboot+vue+mysql员工宿舍管理系统

技术栈 jdk8springboot vueelement-plusMySQL 包含功能点 管理员端 登录员工管理宿舍管理留言板管理物品报修管理公告管理 员工端 登录首页个人中心物品报修留言板 功能截图(部分) 管理员 管理员登录 员工管理 宿舍管理 物品报修管理 公告管理 留言管理 员工 员工登录…

数据库管理-第145期 最强Oracle监控EMCC深入使用-02(20240205)

数据库管理145期 2024-02-05 数据库管理-第145期 最强Oracle监控EMCC深入使用-02&#xff08;20240205&#xff09;1 监控方式2 度量配置3 阻塞4 DG监控总结 数据库管理-第145期 最强Oracle监控EMCC深入使用-02&#xff08;20240205&#xff09; 作者&#xff1a;胖头鱼的鱼缸&…

LeetCode、216. 组合总和 III【中等,组合型枚举】

文章目录 前言LeetCode、216. 组合总和 III【中等&#xff0c;组合型枚举】题目类型与分类思路 资料获取 前言 博主介绍&#xff1a;✌目前全网粉丝2W&#xff0c;csdn博客专家、Java领域优质创作者&#xff0c;博客之星、阿里云平台优质作者、专注于Java后端技术领域。 涵盖…

769933-15-5,Biotin aniline,用来标记和检测细胞膜上的特定蛋白质

您好&#xff0c;欢迎来到新研之家 文章关键词&#xff1a;769933-15-5&#xff0c;Biotin aniline&#xff0c;生物素苯胺 一、基本信息 产品简介&#xff1a;Biotin aniline, also known as Biotin aniline, is a molecular probe with strong reactivity. Its uniqueness…

Java设计模式-责任链模式

责任链模式 一、概述二、结构三、案例实现四、优缺点五、源码解析 一、概述 在现实生活中&#xff0c;常常会出现这样的事例&#xff1a;一个请求有多个对象可以处理&#xff0c;但每个对象的处理条件或权限不同。例如&#xff0c;公司员工请假&#xff0c;可批假的领导有部门…

c# List集合操作帮助类

public class ListHelper { #region 赋值转换 /// <summary> /// A实体转换成B实体 /// </summary> /// <typeparam name"T"></typeparam> /// <typeparam name"K"></typep…

代码随想录-背包问题

01 背包 有n件物品和一个最多能背重量为w 的背包。第i件物品的重量是weight[i]&#xff0c;得到的价值是value[i] 。每件物品只能用一次&#xff0c;求解将哪些物品装入背包里物品价值总和最大。 二维dp数组01背包 定义&#xff1a;dp[i][j] 表示从下标为[0-i]的物品里任意取…

TreeSet 集合

TreeSet 集合 1. 概述2. 方法3. 遍历方式4. 两种排序方式4.1 默认排序规则/自然排序4.1.1 概述4.1.2 compareTo()方法4.1.3 代码示例14.1.4 代码示例2 4.2 比较器排序4.2.1 概述4.2.2 compare()方法4.2.3 代码示例14.2.4 代码示例2 4.3 排序方式的对比 5. 注意事项 文章中的部分…

LeetCode、62.不同路径的数目(一)【简单,动态规划或递归】

文章目录 前言LeetCode、62.不同路径的数目(一)【简单&#xff0c;动态规划或递归】题目描述与分类思路思路1&#xff1a;动态规划思路2&#xff1a;递归实现简洁写法补充&#xff1a;2024.1.30 资料获取 前言 博主介绍&#xff1a;✌目前全网粉丝2W&#xff0c;csdn博客专家、…

程序员好用的软件/网页推荐

桌面&#xff1a;编程&#xff1a; VsCode 插件&#xff1a;python、通义灵码 写文章&#xff1a; PDF公式转MarkDown&#xff1a;https://mathpix.com/snipping-tool 欢迎推荐&#xff0c;持续更新

containerd中文翻译系列(六)内容流

内容流 containerd 的一个主要目标是创建一个可将内容用于执行容器的系统。 为了执行该流程&#xff0c;containerd 需要内容并对其进行管理。 本文档描述了内容如何流入 containerd、如何对其进行管理&#xff0c;以及在此过程中的每个阶段它存在于何处。 我们以从已知镜像 …

自学Java的第二十天

一&#xff0c;每日收获 1.使用方式 1: 动态初始化 2.使用方式 2: 动态初始化 3.使用方式 3: 动态初始化-列数不确定 4.使用方式 4: 静态初始化 5.二维数组的应用案例 6.二维数组使用细节和注意事项 二&#xff0c;新名词与小技巧 三&#xff0c;今天学习中所遇到的困难…

代理与Reflect反射

属性描述符 Proprety Descriptor 属性描述符 用于描述一个属性的相关信息 1.Object.getOwnPropertyDescriptor(对象&#xff0c;属性名) 可以得到一个对象的 某个属性的属性描述符 Object.getOwnPropertyDescriptors(对象) 可以得到某个对象的所有属性描述符 如果需要为某个…

(已解决)vue+element-ui实现个人中心,仿照原神

差一个个人中心页面&#xff0c;看到了这个博主的个人中心&#xff0c;真的很不错 地址&#xff1a;vueelement仿原神实现好看的个人中心 最终效果&#xff1a;

TypeScript快速入门 - 函数的使用

1、有名函数和匿名函数 // 有名函数,形参设置为number类型,返回值也为number类型 function add(x: number, y: number): number {return x y; } console.log(add(1, 2)); // 3//匿名函数,形参设置为number类型,返回值也为number类型 let myAdd function (x: number, y: numb…

【多模态MLLMs+图像编辑】MGIE:苹果开源基于指令和大语言模型的图片编辑神器(24.02.03开源)

项目主页&#xff1a;https://mllm-ie.github.io/ 论文 :基于指令和多模态大语言模型图片编辑 2309.Guiding Instruction-based Image Editing via Multimodal Large Language Models &#xff08;加州大学圣巴拉分校苹果&#xff09; 代码&#xff1a;https://github.com/appl…

rtt设备驱动框架学习-spi总线和设备

1.spi总线 spi总线分为硬件spi总线和软件模拟spi总线。 按照面向对象的思想&#xff0c;要抽象出硬件spi总线和软件spi总线的相同点和不同点。相同点就变成了spi总线基类&#xff0c;不同点就是各个子类的私有特性。 rtt就是这么干的&#xff0c;共同点是什么&#xff1f;方法…

理解new BigDecimal(double)和BingDecinal.valueOf(double)的区别

在Java中&#xff0c;BigDecimal类常用于精确的小数运算&#xff0c;尤其是在需要高精度计算的金融领域。使用BigDecimal时&#xff0c;创建其实例的方式对最终结果的准确性有重要影响。new BigDecimal(double)和BigDecimal.valueOf(double)是创建BigDecimal对象的两种常用方法…

【2024.2.5练习】砍竹子(25分)

题目描述 题目分析 考虑题目是否满足贪心。每次施展魔法会使一段连续的竹子高度变为一半左右的平方根。根据样例&#xff0c;似乎每次让最高的竹子变短就能得到最优解。 假设魔法一次只能对一根竹子使用&#xff0c;永远不出现连续相同高度的竹子&#xff0c;那么显然无论使用…

电商开放API商品采集接口、关键字搜索接口,获取商品ID、商品主图接口

API是application programming interface&#xff08;应用程序接口&#xff09;的简称&#xff0c;是一些预先定义的函数&#xff0c;目的是提供应用程序与开发人员基于某软件或硬件的以访问一组例程的能力&#xff0c;而又无需访问源码&#xff0c;或理解内部工作机制的细节。…