Vue 商场首页头部布局

news2024/9/18 17:31:27

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

封装基础网络请求,前后端联调请求后端接口

npm install axios -S

src/network/requestConfig.js

import axios from 'axios';
import store from "@/store";
export function request(config){
	const instance = axios.create({
		baseURL:"http://127.0.0.1:8000/",
		// baseURL:process.env.VUE_APP_BASE_URL,
		timeout:5000,
	})
	
	// 请求拦截
	instance.interceptors.request.use(config=>{
		// 一般来说我们会在这里边给一些实例加上token
		const token = window.localStorage.getItem("token");
		if(token){
			// config.headers.Authorization="token";
			config.headers.Authorization=token;
		}
		
		// 直接放行
		return config;
	},err=>{
		// 这里写一些错误的代码在这里
	})
	
	// 响应拦截
	instance.interceptors.response.use(res=>{
		if(res.data.status==false){
			window.localStorage.setItem("token","");
			store.commit("setIsLogin",false);
		}

		return res.data?res.data:res;
	},err=>{
		// 响应错误的在这里处理,比如404  500这些特殊的状态码
		// 咱们跳转一个特定的处理页面
	})
	
	return instance(config);
} 

src/network/home.js

import {request} from "./requestConfig.js"


export function getMainMenu(){
	return request({
		url:"/main_menu",
	})
}

测试


<script setup>
	import {getMainMenu} from "@/network/home"
	getMainMenu().then(res=>{
		console.log(res)
	})
</script>

在这里插入图片描述

配置基础 router 信息

src/router/index.js

import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta:{
      title:"慕西商城首页"
    }
  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to,from)=>{
	document.title = to.meta.title;
})

export default router

src/views/HomeView.vue

<template>
    <p>首页</p>
</template>

在这里插入图片描述

慕西商城首页顶层标题栏开发

在这里插入图片描述

src/assets/css/config.css
全局配置

@import './base.css';
/*定义全局变量*/
:root {
    --font-red: #f10215;
    --font-gray: #999;
    --content-width:1200px;
	--el-color-danger:#e2231a !important;
}

main.js
全局引入

import "@/assets/css/config.css"

这个宽度是1200 引用在src/assets/css/config.css全局中设置–content-width
在这里插入图片描述

<template>
    <div class="wrapper">
        <div class="header">
            <a href="#">你好,请登录</a>
             <a href="#">免费注册</a> |
              <a href="#">我的订单</a>
        </div>
    </div>
</template>

<style lang="less" scoped>
    //最外层
    .wrapper{
        background-color: #e3e4e5;
        height: 30px;
        .header{
            //引用全局变量中的宽度变量
            width: var(--content-width);
            margin: 0 auto;   //居中
            text-align: right; //右对齐
            line-height: 30px;  //上下对齐
            a{
                color: var(--font-gray);
                // 鼠标滑过的效果
                &:hover{
                    color: var(--font-red);
                }
                margin-left: 10px;
            }

        }
    }
</style>

在这里插入图片描述

取地址符空格增加免费注册和右边分割线的距离

<a href="#">免费注册</a> &nbsp;&nbsp;|

在这里插入图片描述

也可以把免费注册设置为一直是红色的
在这里插入图片描述

慕西商城首页头部结构开发

在这里插入图片描述

components/home/Header.vue

<template>
    <div class="main">
        <div class="content">
            <div class="logo">
                我是logo

            </div>
            <div class="search-box">
                我是搜索框
            </div>
            <div class="right">
                我是右侧的图片
            </div>

        </div>
    </div>
</template>

<script>

</script>

<style lang="less" scoped>
    .main{
        .content{
            width: var(--content-width);
            margin: 0 auto;   //居中对其
            height: 140px;
        }
    }

</style>

views/HomeView.vue 中引入

<template>
    <div>
        <Shortcut></Shortcut>
        <Header></Header>
        <div>
            我是主页
        </div>
    </div>
</template>

<script setup>
import Shortcut from "@/components/common/Shortcut.vue"
import Header from "@/components/home/Header"

</script>

在这里插入图片描述
让标签浮动,在一行显示
在这里插入图片描述
在这里插入图片描述

<template>
    <div class="main">
        <div class="content">
            <div class="logo fl">
                <Logo></Logo>

            </div>
            <div class="search-box fl">
                我是搜索框
            </div>
            <div class="right fl">
                <img src="@/assets/images/header-right.png"> 
            </div>

        </div>
    </div>
</template>

<script setup>
import Logo from "@/components/common/Logo.vue"
</script>

<style lang="less" scoped>
    .main{
        .content{
            width: var(--content-width);
            margin: 0 auto;   //居中对其
            height: 140px;
            border: 1px solid red;
        }

        .search-box{
            width: 800px;
        }
        .right{
            img{
                width:200px;
            }
            line-height: 140px;
        }
    }

</style>

common/Logo.vue

<template>
    <div>
        <img class="logo" src="@/assets/images/logo/logo-big.png" alt="">
    </div>
</template>



<style scoped lang="less">
div{
    .logo{
        width: 100px;
        height: 100px;
    }
    line-height: 140px;
}
    
</style>

在这里插入图片描述
可以让右边的图片再往右靠边

在这里插入图片描述
在这里插入图片描述

慕西商城首页头部搜索框开发

src/components/home/Header.vue

<template>
  <div class="main">
    <div class="content">
      <div class="logo fl">
        <Logo></Logo>
      </div>
      <div class="search-box fl">
        <div class="input-search fl">
          <SearchBox></SearchBox>
        </div>
      </div>
      <div class="right fr">
        <img src="@/assets/images/header-right.png" />
      </div>
    </div>
  </div>
</template>

<script setup>
import Logo from "@/components/common/Logo.vue";
import SearchBox from "@/components/home/SearchBox.vue";
</script>

<style lang="less" scoped>
.main {
  .content {
    width: var(--content-width);
    margin: 0 auto; //居中对其
    height: 140px;
    // border: 1px solid red;
  }

  .search-box {
    width: 800px;
    height: 70px;
  }
  .right {
    img {
      width: 200px;
    }
    line-height: 140px;
  }
}
</style>

home/SearchBox.vue

<template>
  <div class="main">
    <div class="content">
      <input type="text" placeholder="请输入搜索条件" />
      <span class="iconfont icon-fangdajing"></span>
    </div>

    <div class="hotword">
      <a
        v-for="(item, key) in hotWords"
        :key="key"
        :class="item.active === true ? 'active' : ''"
        href="#"
        >{{ item.word }}</a
      >
    </div>
  </div>
</template>



<script setup>
import { ref } from "vue";
const hotWords = ref([
  { word: "电脑", active: true },
  { word: "手记", active: false },
  { word: "裙子", active: false },
  { word: "空调", active: false },
  { word: "裤子", active: false },
]);
</script>

<style scoped lang="less">
@red: #e2231a;
.main {
  height: 140px;
  margin-top: 45px;
  .content {
    width: 550px;
    height: 35px;
    border: 2px solid @red;
    margin-left: 80px; //距左边logo距离
    input {
      width: 485px;
      line-height: 35px;
      height: 35px;
      padding-left: 15px;
    }
    span {
      display: inline-block;
      background-color: @red;
      width: 50px;
      height: 35px;
      line-height: 35px;
      text-align: center;
      color: white;
      font-weight: 700;
      &:hover {
        cursor: pointer;
        background-color: #c81623;
      } //搜索按钮有颜色渐变的效果
    }
    .hotword {
      margin-right: 300px;
      margin-top: 10px;
      a {
        color: #999;
        margin-right: 10px;
        &:hover {
          color: @red;
        }
      }
      .active {
        color: @red;
      }
    }
  }
}
</style>

在这里插入图片描述

Element-Plus 简介与安装

npm install element-plus --save

main.js

// 引入element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

慕西商城首页头部我的购物车开发

在这里插入图片描述

home/ShopCart.vue

<template>
  <div class="main">
    <div class="shopcart">
      <el-badge :value="12" class="item">
        <span class="iconfont icon-gouwuche"></span>
      </el-badge>

      <span>我的购物车</span>
    </div>
  </div>
</template>


<style scoped lang="less">
@red: #e2231a;
.main {
  height: 140px;
  margin-top: 45px;
  margin-left: 20px;
  .shopcart{
    border: 1px solid #e3e4e5;
    width: 130px;
    height: 35px;
    line-height: 35px;
    text-align: center;
    padding-top: 4px;
    .item{
        height: 25px;
        line-height: 25px;
        >span{
            color: @red;
            font-weight: 700;
        }
        
    }
    &:hover{
            cursor: pointer;
            border: 1px solid @red;
        }
    >span{
        margin-left: 20px;
        color: @red;
    }

  }
}
</style>

home/header.vue

<template>
  <div class="main">
    <div class="content">
      <div class="logo fl">
        <Logo></Logo>
      </div>
      <div class="search-box fl">
        <div class="input-search fl">
          <SearchBox></SearchBox>
        </div>
        <div class="shopcart fl">
          <ShopCart></ShopCart>
        </div>
      </div>
      <div class="right fr">
        <img src="@/assets/images/header-right.png" />
      </div>
    </div>
  </div>
</template>

在这里插入图片描述

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

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

相关文章

用GoAccess可视化监控npm日志

什么是 GoAccess&#xff1f; GoAccess 是一个开源实时 Web 日志分析器和交互式查看器&#xff0c;可在 *nix 系统的终端中或通过浏览器运行。它为需要动态可视化服务器报告的系统管理员提供快速且有价值的 HTTP 统计信息。 什么是 GoAccess for Nginx Proxy Manager Logs? Go…

【C++入门到精通】 哈希结构 | 哈希冲突 | 哈希函数 | 闭散列 | 开散列 [ C++入门 ]

阅读导航 引言一、哈希概念二、哈希冲突三、哈希函数⭕哈希函数应具备的特点⭕哈希函数设计原则⭕常见的哈希函数&#xff08;1&#xff09;直接定址法&#xff08;重要&#xff09;&#xff08;2&#xff09;除留余数法&#xff08;重要&#xff09;&#xff08;3&#xff09;…

详解预处理(1)

目录 预定义符号 预处理指令#define #define定义符号 #define定义宏 #define替换规则 #和##&#xff08;C语言预处理操作符&#xff09; # ## 带副作用的宏参数 宏和函数的对比 命名约定 在之前我们学习了一个文本文件.c生成一个可执行程序。今天我们详细讲解其中的…

BUUCTF 基础破解 1

BUUCTF:https://buuoj.cn/challenges 题目描述&#xff1a; 给你一个压缩包&#xff0c;你并不能获得什么&#xff0c;因为他是四位数字加密的哈哈哈哈哈哈哈。。。不对 我说了什么了不得的东西。。 密文&#xff1a; 下载附件解压&#xff0c;发现一个rar压缩包。 解题思…

C++项目:网络版五子棋对战(收官总结篇)

文章目录 一、项目背景&#xff08;一&#xff09;用户管理&#xff08;二&#xff09;匹配对战&#xff08;三&#xff09;聊天功能 二、开发环境三、核心技术四、项目大流程五、项目模块介绍&#xff08;一&#xff09;实用工具类模块1.意义2.设计 &#xff08;二&#xff09…

FLStudio2024最新破解版注册机

水果音乐制作软件FLStudio是一款功能强大的音乐创作软件,全名:Fruity Loops Studio。水果音乐制作软件FLStudio内含教程、软件、素材,是一个完整的软件音乐制作环境或数字音频工作站... FL Studio21简称FL 21&#xff0c;全称 Fruity Loops Studio 21&#xff0c;因此国人习惯叫…

当vCenter的证书过期、Root密码过期、Root密码遗忘同时发生时的解决方法与步骤

文章目录 当vCenter的MACHINE证书过期、Root密码过期、权限SSO User密码与Root密码遗忘同时发生时的解决方法与步骤1. 强制修改Root密码2. 强制重新生成权限SSO User的密码3、解决证书过期的问题 当vCenter的MACHINE证书过期、Root密码过期、权限SSO User密码与Root密码遗忘同时…

用别人的网站多不舒服,自己手撸一个密码批量生成器网站

自己手撸一个密码批量生成器网站 自己手撸一个密码生成器网站 小编可以这样给你说&#xff0c;这个是最简单的拉&#xff0c;没有任何的装饰&#xff0c;简单容易上手&#xff0c;还是经过小编测试过的哈 python版本django版本python3.8.6Django3.0.5 声明 这个代码也就是小编…

应用程序架构是如何演变的

【squids.cn】 全网zui低价RDS&#xff0c;免费的迁移工具DBMotion、数据库备份工具DBTwin、SQL开发工具等 如果您一直在开发或以某种方式参与应用程序架构&#xff0c;那么在过去的几年中您肯定看到了许多变化。有很多不同类型的架构和技术陆续出现然后消失&#xff0c;以至于…

Windows端口封禁图文教程

文章目录 方式一&#xff1a;打开secpol.msc方式二&#xff1a;Microsoft 管理控制台参考文档 方式一&#xff1a;打开secpol.msc WIN键R输入secpol.msc 在本地安全策略窗口中&#xff0c;选中“IP安全策略&#xff0c;在本地计算机”&#xff0c;右键右侧空白处&#xff0c;选…

ubuntu2004上安装openjdk6

今天因为工作需要要在Ubuntu2004上安装openjdk6&#xff0c;还是有点麻烦的. 这里记录一下过程。 Step 1&#xff1a; openjdk的下载地址在这里&#xff0c;选择对应的架构并将openjdk开头的包全部下载回来。 Step 2&#xff1a; 安装的时候系统缺少以下依赖&#xff1a; …

3d模型轻量化方法以及工具平台

3D模型轻量化是指减少3D模型的文件大小&#xff0c;以便在需要更快的数据传输或更快的渲染速度时使用。 一、以下是几种常见的3D模型轻量化方法&#xff1a; 1、移除不必要的细节&#xff1a;模型中可能存在一些细节&#xff0c;但这些细节对于渲染或使用模型并不重要。通过移…

基于springboot实现乐校园二手书交易管理系统【项目源码+论文说明】

基于springboot实现乐校园二手书交易管理系统演示 摘要 在Internet高速发展的今天&#xff0c;我们生活的各个领域都涉及到计算机的应用&#xff0c;其中包括乐校园二手书交易管理系统的网络应用&#xff0c;在外国二手书交易管理系统已经是很普遍的方式&#xff0c;不过国内的…

如何实现两栏布局?这篇文章告诉你所有的细节!

&#x1f3ac; 江城开朗的豌豆&#xff1a;个人主页 &#x1f525; 个人专栏 :《 VUE 》 《 javaScript 》 &#x1f4dd; 个人网站 :《 江城开朗的豌豆&#x1fadb; 》 ⛺️ 生活的理想&#xff0c;就是为了理想的生活 ! 目录 ⭐ 专栏简介 &#x1f4d8; 文章引言 一、背…

031-从零搭建微服务-监控中心(一)

写在最前 如果这个项目让你有所收获&#xff0c;记得 Star 关注哦&#xff0c;这对我是非常不错的鼓励与支持。 源码地址&#xff08;后端&#xff09;&#xff1a;mingyue: &#x1f389; 基于 Spring Boot、Spring Cloud & Alibaba 的分布式微服务架构基础服务中心 源…

正点原子嵌入式linux驱动开发——外置RTC芯片PCF8563

上一章学习了STM32MP1内置RTC外设&#xff0c;了解了Linux系统下RTC驱动框架。一般的应用场合使用SOC内置的RTC就可以了&#xff0c;而且成本也低&#xff0c;但是在一些对于时间精度要求比较高的场合&#xff0c;SOC内置的RTC就不适用了。这个时候需要根据自己的应用要求选择合…

Halcon 常用通道Scale灰度元操作整理

一、说明 我们将常见的,基于图层信号幅度的操作集中展现出来,以便以后见到相关的操作不会产生唐突。至于这些算子在项目中的灵活应用,我们将在项目中具体指定。 二、基于数量(Scale)的操作 2.1 亮度(Scale)调整 scale_image_max(Image:ImageScaleMax::)

微信批量添加好友,让你的人脉迅速增长

在这个数字化时代&#xff0c;微信作为中国最流行的社交平台之一&#xff0c;已经成为了人们生活中不可或缺的一部分。它的广泛使用为我们提供了无限的社交可能性。你是否曾为了扩大人脉圈子而犯愁&#xff1f;今天&#xff0c;我将向你揭示一个高效添加微信好友的秘密武器&…

Camtasia2024破解版百度云网盘下载

真的要被录屏软件给搞疯了&#xff0c;本来公司说要给新人做个培训视频&#xff0c;想着把视频录屏一下&#xff0c;然后简单的剪辑一下就可以了。可谁知道录屏软件坑这么多&#xff0c;弄来弄去头都秃了&#xff0c;不过在头秃了几天之后&#xff0c;终于让我发现了一个值得“…

居舍系列再续“异国的相遇2023”艺术项目

跨越四城感知艺术声浪&#xff0c;以科技与艺术探索旅行中的情绪共鸣 太古酒店集团旗下居舍系列再度开启两年一度的艺术项目“异国的相遇 2023”&#xff08;Encounters Across Cultures&#xff09;新篇章 — 当艺术与科技同频 &#xff0c;以艺术为媒介&#xff0c;将科技赋予…