vue黑马之小兔鲜首页组件案例

素材领取:点我领取素材
提取码:1024

页面开发思路:
1.分析页面,按模块拆分组件,搭架子 (局部或全局注册)
2.根据设计图,编写组件html 结构 css 样式(已准备好)
3.拆分封装通用小组件 (局部或全局注册将来>通过js动态染,实现功能

父组件代码:

<template>
  <div class="App">
    
    <XtxShortCut>XtxShortCut>
    
    <XtxHeaderNav>XtxHeaderNav>
    
    <XtxBanner>XtxBanner>
    
    <XtxNewGoods>XtxNewGoods>
    
    <XtxHotBrand>XtxHotBrand>
    
    <XtxTopic>XtxTopic>
    
    <XtxFooter>XtxFooter>
  div>
template>

<script>
import XtxShortCut from "./components/XtxShortCut.vue"
import XtxHeaderNav from "./components/XtxHeaderNav.vue"
import XtxBanner from "./components/XtxBanner.vue"
import XtxNewGoods from "./components/XtxNewGoods.vue"
import XtxHotBrand from "./components/XtxHotBrand.vue"
import XtxTopic from "./components/XtxTopic.vue"
import XtxFooter from "./components/XtxFooter.vue"
export default {
  name: 'VueApp',
  components: {
    XtxShortCut,
    XtxHeaderNav,
    XtxBanner,
    XtxNewGoods,
    XtxHotBrand,
    XtxTopic,
    XtxFooter
  }
};
script>

<style lang="scss" scoped>style>

子组件XtxShortCut代码:

<template>
    
    <div class="shortcut">
        <div class="wrapper">
            <ul>
                <li><a href="#" class="login">请先登录a>li>
                <li><a href="#">免费注册a>li>
                <li><a href="#">我的订单a>li>
                <li><a href="#">会员中心a>li>
                <li><a href="#">帮助中心a>li>
                <li><a href="#">在线客服a>li>
                <li>
                    <a href="#"><span class="iconfont icon-mobile-phone">span>手机版a>
                li>
            ul>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxShortCut',
};
script>

<style scoped>
/* 快捷导航 */
.shortcut {
    height: 52px;
    line-height: 52px;
    background-color: #333;
}

.shortcut .wrapper {
    display: flex;
    justify-content: flex-end;
}

.shortcut ul {
    display: flex;
}

.shortcut a {
    padding: 0 15px;
    border-right: 1px solid #999;
    color: #fff;
    font-size: 14px;
    line-height: 14px;
}

.shortcut .login {
    color: #5EB69C;
}

.shortcut .icon-mobile-phone {
    margin-right: 5px;
}
style>

子组件XtxHeaderNav代码:

<template>
    
    <div class="header wrapper">
        
        <div class="logo">
            <h1>
                <a href="#">小兔鲜儿a>
            h1>
        div>
        
        <div class="nav">
            <ul>
                <li><a href="#">首页a>li>
                <li><a href="#">生鲜a>li>
                <li><a href="#">美食a>li>
                <li><a href="#">餐厨a>li>
                <li><a href="#">电器a>li>
                <li><a href="#">居家a>li>
                <li><a href="#">洗护a>li>
                <li><a href="#">孕婴a>li>
                <li><a href="#">服装a>li>
            ul>
        div>
        
        <div class="search">
            <span class="iconfont icon-search">span>
            <input type="text" placeholder="搜一搜" />
        div>
        
        <div class="cart">
            <span class="iconfont icon-cart-full">span>
            <i>2i>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxHeaderNav',
};
script>

<style scoped>
/* 头部导航 */
.header {
    display: flex;
    margin: 22px auto;
}

.header .logo {
    margin-right: 40px;
    width: 200px;
    height: 88px;
    background-color: pink;
}

.header .logo a {
    display: block;
    width: 200px;
    height: 88px;
    background-image: url(~@/assets/images/logo.png);
    font-size: 0;
}

.header .nav {
    margin-top: 33px;
    margin-right: 27px;
}

.header .nav ul {
    display: flex;
}

.header .nav li {
    margin-right: 48px;
}

.header .nav a {
    display: block;
    height: 34px;
}

.header .nav a:hover {
    border-bottom: 2px solid #5EB69C;
}

.header .search {
    display: flex;
    margin-right: 45px;
    margin-top: 33px;
    width: 170px;
    height: 34px;
    border-bottom: 2px solid #F4F4F4;
}

.header .search .icon-search {
    margin-right: 8px;
    font-size: 20px;
    color: #999;
}

.header .search input {
    flex: 1;
}

.header .search input::placeholder {
    color: #ccc;
}

.header .cart {
    position: relative;
    margin-top: 33px;
}

.header .cart .icon-cart-full {
    font-size: 24px;
}

.header .cart i {
    position: absolute;
    /* right: -5px; */
    left: 15px;
    top: 0;
    padding: 0 5px;
    height: 15px;
    background-color: #E26237;
    border-radius: 7px;
    font-size: 12px;
    color: #fffefe;
    line-height: 15px;
}
style>

子组件XtxBanner代码:

<template>
    
    <div class="banner">
        <div class="wrapper">
            
            <ul class="pic">
                <li>
                    <a href="#"><img src="@/assets/images/banner1.png" alt="" />a>
                li>
                <li>
                    <a href="#"><img src="@/assets/images/banner1.png" alt="" />a>
                li>
            ul>
            
            <div class="subnav">
                <ul>
                    <li>
                        <div>
                            <span><a href="#">生鲜a>span>
                            <span><a href="#">水果a><a href="#">蔬菜a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">美食a>span>
                            <span><a href="#">面点a><a href="#">干果a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">餐厨a>span>
                            <span><a href="#">数码产品a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">电器a>span>
                            <span><a href="#">床品a><a href="#">四件套a><a href="#">被枕a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">居家a>span>
                            <span><a href="#">奶粉a><a href="#">玩具a><a href="#">辅食a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">洗护a>span>
                            <span><a href="#">洗发a><a href="#">洗护a><a href="#">美妆a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">孕婴a>span>
                            <span><a href="#">奶粉a><a href="#">玩具a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">服饰a>span>
                            <span><a href="#">女装a><a href="#">男装a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">杂货a>span>
                            <span><a href="#">户外a><a href="#">图书a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                    <li>
                        <div>
                            <span><a href="#">品牌a>span>
                            <span><a href="#">品牌制造a>span>
                        div>
                        <i class="iconfont icon-arrow-right-bold">i>
                    li>
                ul>
            div>
            
            <ol>
                <li class="current"><i>i>li>
                <li><i>i>li>
                <li><i>i>li>
            ol>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxBanner',
};
script>

<style scoped>
/* 轮播区域 */
.banner {
    height: 500px;
    background-color: #F5F5F5;
}

.banner .wrapper {
    position: relative;
    overflow: hidden;
}

.banner .pic {
    display: flex;
    width: 3720px;
    height: 500px;
}

.banner .pic li {
    width: 1240px;
    height: 500px;
}

.banner .subnav {
    position: absolute;
    left: 0;
    top: 0;
    width: 250px;
    height: 500px;
    background-color: rgba(0, 0, 0, 0.42);
}

.banner .subnav li {
    display: flex;
    justify-content: space-between;
    padding: 0 20px 0 30px;
    height: 50px;
    line-height: 50px;
}

.banner .subnav a,
.banner .subnav i {
    color: #fff;
}

.banner .subnav li span:nth-child(1) {
    margin-right: 14px;
}

.banner .subnav li span:nth-child(2) a {
    margin-right: 5px;
}

.banner .subnav li span:nth-child(2) a {
    font-size: 14px;
}

.banner .subnav li:hover {
    background-color: #00BE9A;
}

.banner ol {
    position: absolute;
    right: 17px;
    bottom: 17px;
    display: flex;
}

.banner ol li {
    cursor: pointer;
    margin-left: 8px;
    padding: 4px;
    width: 22px;
    height: 22px;
    background-color: transparent;
    border-radius: 50%;
}

.banner ol li i {
    display: block;
    width: 14px;
    height: 14px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
}

.banner ol .current {
    background-color: rgba(255, 255, 255, 0.5);
}

.banner ol .current i {
    background-color: #fff;
}
style>

子组件XtxNewGoods代码:

<template>
    
    <div class="goods wrapper">
        <div class="title">
            <div class="left">
                <h3>新鲜好物h3>
                <p>新鲜出炉 品质靠谱p>
            div>
            <div class="right">
                <a href="#" class="more">查看全部<span class="iconfont icon-arrow-right-bold">span>a>
            div>
        div>
        <div class="bd">
            <ul>
                <li>
                    <a href="#">
                        <div class="pic"><img src="@/assets/images/goods1.png" alt="" />div>
                        <div class="txt">
                            <h4>KN95级莫兰迪色防护口罩h4>
                            <p>¥ <span>79span>p>
                        div>
                    a>
                li>
                <li>
                    <a href="#">
                        <div class="pic"><img src="@/assets/images/goods2.png" alt="" />div>
                        <div class="txt">
                            <h4>KN95级莫兰迪色防护口罩h4>
                            <p>¥ <span>566span>p>
                        div>
                    a>
                li>
                <li>
                    <a href="#">
                        <div class="pic"><img src="@/assets/images/goods3.png" alt="" />div>
                        <div class="txt">
                            <h4>法拉蒙高颜值记事本可定制h4>
                            <p>¥ <span>58span>p>
                        div>
                    a>
                li>
                <li>
                    <a href="#">
                        <div class="pic"><img src="@/assets/images/goods4.png" alt="" />div>
                        <div class="txt">
                            <h4>科技布布艺沙发h4>
                            <p>¥ <span>3759span>p>
                        div>
                    a>
                li>
            ul>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxNewGoods',
};
script>

<style scoped>
/* 新鲜好物 */
.goods .bd ul {
    display: flex;
    justify-content: space-between;
}

.goods .bd li {
    width: 304px;
    height: 404px;
    background-color: #EEF9F4;
}

.goods .bd li {
    display: block;
}

.goods .bd li .pic {
    width: 304px;
    height: 304px;
}

.goods .bd li .txt {
    text-align: center;
}

.goods .bd li h4 {
    margin-top: 17px;
    margin-bottom: 8px;
    font-size: 20px;
}

.goods .bd li p {
    font-size: 18px;
    color: #AA2113;
}

.goods .bd li p span {
    font-size: 22px;
}
style>

子组件XtxHotBrand代码:

<template>
    
    <div class="hot">
        <div class="wrapper">
            <div class="title">
                <div class="left">
                    <h3>热门品牌h3>
                    <p>国际经典 品质认证p>
                div>
                <div class="button">
                    <a href="#"><i class="iconfont icon-arrow-left-bold">i>a>
                    <a href="#"><i class="iconfont icon-arrow-right-bold">i>a>
                div>
            div>
            <div class="bd">
                <ul>
                    <li>
                        <a href="#">
                            <img src="@/assets/images/hot1.png" alt="" />
                        a>
                    li>
                    <li>
                        <a href="#">
                            <img src="@/assets/images/hot2.png" alt="" />
                        a>
                    li>
                    <li>
                        <a href="#">
                            <img src="@/assets/images/hot3.png" alt="" />
                        a>
                    li>
                    <li>
                        <a href="#">
                            <img src="@/assets/images/hot4.png" alt="" />
                        a>
                    li>
                    <li>
                        <a href="#">
                            <img src="@/assets/images/hot5.png" alt="" />
                        a>
                    li>
                ul>
            div>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxHotBrand',
};
script>

<style scoped>
/* 热门品牌 */
.hot {
    margin-top: 60px;
    padding-bottom: 40px;
    overflow: hidden;
    background-color: #F5F5F5;
}

.hot .title {
    position: relative;
    margin-bottom: 40px;
}

.hot .button {
    display: flex;
    position: absolute;
    right: 0;
    top: 47px;
}

.hot .button a {
    display: block;
    width: 20px;
    height: 20px;
    background-color: #ddd;
    text-align: center;
    line-height: 20px;
    color: #fff;
}

.hot .button a:nth-child(2) {
    margin-left: 12px;
    background-color: #00BE9A;
}

.hot .bd ul {
    display: flex;
    justify-content: space-between;
}

.hot .bd li {
    width: 244px;
    height: 306px;
}
style>

子组件XtxTopic代码:

<template>
    
    <div class="topic wrapper">
        <div class="title">
            <div class="left">
                <h3>最新专题h3>
            div>
            <div class="right">
                <a href="#" class="more">查看全部<span class="iconfont icon-arrow-right-bold">span>a>
            div>
        div>
        <div class="topic_bd">
            <ul>
                <li>
                    <a href="#">
                        <div class="pic">
                            <img src="@/assets/images/topic1.png" alt="" />
                            <div class="info">
                                <div class="left">
                                    <h5>吃这些美食才不算辜负自己h5>
                                    <p>餐厨起居洗护好物p>
                                div>
                                <div class="right">¥<span>29.9span>div>
                            div>
                        div>
                        <div class="txt">
                            <div class="left">
                                <p>
                                    <span class="iconfont icon-favorites-fill red">span>
                                    <i>1200i>
                                p>
                                <p>
                                    <span class="iconfont icon-browse">span>
                                    <i>1800i>
                                p>
                            div>
                            <div class="right">
                                <span class="iconfont icon-comment">span>
                                <i>246i>
                            div>
                        div>
                    a>
                li>
                <li>
                    <a href="#">
                        <div class="pic">
                            <img src="@/assets/images/topic2.png" alt="" />
                            <div class="info">
                                <div class="left">
                                    <h5>吃这些美食才不算辜负自己h5>
                                    <p>餐厨起居洗护好物p>
                                div>
                                <div class="right">¥<span>29.9span>div>
                            div>
                        div>
                        <div class="txt">
                            <div class="left">
                                <p>
                                    <span class="iconfont icon-fabulous">span>
                                    <i>1200i>
                                p>
                                <p>
                                    <span class="iconfont icon-browse">span>
                                    <i>1800i>
                                p>
                            div>
                            <div class="right">
                                <span class="iconfont icon-comment">span>
                                <i>246i>
                            div>
                        div>
                    a>
                li>
                <li>
                    <a href="#">
                        <div class="pic">
                            <img src="@/assets/images/topic3.png" alt="" />
                            <div class="info">
                                <div class="left">
                                    <h5>吃这些美食才不算辜负自己h5>
                                    <p>餐厨起居洗护好物p>
                                div>
                                <div class="right">¥<span>29.9span>div>
                            div>
                        div>
                        <div class="txt">
                            <div class="left">
                                <p>
                                    <span class="iconfont icon-fabulous">span>
                                    <i>1200i>
                                p>
                                <p>
                                    <span class="iconfont icon-browse">span>
                                    <i>1800i>
                                p>
                            div>
                            <div class="right">
                                <span class="iconfont icon-comment">span>
                                <i>246i>
                            div>
                        div>
                    a>
                li>
            ul>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxTopic',
};
script>

<style scoped>
/* 最新专题 */
.topic {
    padding-top: 60px;
    margin-bottom: 40px;
}

.topic_bd ul {
    display: flex;
    justify-content: space-between;
}

.topic_bd li {
    width: 405px;
    height: 355px;
}

.topic_bd .pic {
    position: relative;
    width: 405px;
    height: 288px;
}

.topic_bd .txt {
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    height: 67px;
    line-height: 67px;
    color: #666;
    font-size: 14px;
}

.topic_bd .txt .left {
    display: flex;
}

.topic_bd .txt .left p {
    margin-right: 20px;
}

.topic_bd .txt .left .red {
    color: #AA2113;
}

.topic_bd .info {
    position: absolute;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    width: 100%;
    height: 90px;
    background-image: linear-gradient(180deg, rgba(137, 137, 137, 0.00) 0%, rgba(0, 0, 0, 0.90) 100%);
}

.topic_bd .info .left {
    padding-top: 20px;
    color: #fff;
}

.topic_bd .info .left h5 {
    margin-bottom: 5px;
    font-size: 20px;
}

.topic_bd .info .right {
    margin-top: 35px;
    padding: 0 7px;
    height: 25px;
    line-height: 25px;
    background-color: #fff;
    color: #AA2113;
    font-size: 15px;
}
style>

子组件XtxFooter代码:

<template>
    
    <div class="footer">
        <div class="wrapper">
            <div class="service">
                <ul>
                    <li>
                        <span>span>
                        <p>价格亲民p>
                    li>
                    <li>
                        <span>span>
                        <p>物流快捷p>
                    li>
                    <li>
                        <span>span>
                        <p>品质新鲜p>
                    li>
                    <li>
                        <span>span>
                        <p>售后无忧p>
                    li>
                ul>
            div>
            <div class="help">
                <div class="left">
                    <dl>
                        <dt>购物指南dt>
                        <dd><a href="#">购物流程a>dd>
                        <dd><a href="#">支付方式a>dd>
                        <dd><a href="#">售后规则a>dd>
                    dl>
                    <dl>
                        <dt>配送方式dt>
                        <dd><a href="#">配送运费a>dd>
                        <dd><a href="#">配送范围a>dd>
                        <dd><a href="#">配送时间a>dd>
                    dl>
                    <dl>
                        <dt>关于我们dt>
                        <dd><a href="#">平台规则a>dd>
                        <dd><a href="#">联系我们a>dd>
                        <dd><a href="#">问题反馈a>dd>
                    dl>
                    <dl>
                        <dt>售后服务dt>
                        <dd><a href="#">售后政策a>dd>
                        <dd><a href="#">退款说明a>dd>
                        <dd><a href="#">取消订单a>dd>
                    dl>
                    <dl>
                        <dt>服务热线dt>
                        <dd>
                            <a href="#">在线客服<span class="iconfont icon-customer-service">span>a>
                        dd>
                        <dd><a href="#">客服电话 400-0000-000a>dd>
                        <dd><a href="#">工作时间 周一至周日 8:00-18:00a>dd>
                    dl>
                div>
                <div class="right">
                    <ul>
                        <li>
                            <div><img src="@/assets/images/wechat.png" alt="" />div>
                            <p>微信公众号p>
                        li>
                        <li>
                            <div><img src="@/assets/images/app.png" alt="" />div>
                            <p>APP下载二维码p>
                        li>
                    ul>
                div>
            div>
            <div class="copyright">
                <p>
                    <a href="#">关于我们a>|<a href="#">帮助中心a>|<a href="#">售后服务a>|<a href="#">配送与验收a>|<a
                        href="#">商务合作a>|<a href="#">搜索推荐a>|<a href="#">友情链接a>
                p>
                <p>CopyRight © 小兔鲜p>
            div>
        div>
    div>
template>

<script>
export default {
    name: 'VueXtxFooter',
};
script>

<style scoped>
/* 版权底部 */
.footer {
    height: 580px;
    background-color: #F5F5F5;
}

.footer .service {
    padding: 60px 0;
    height: 180px;
    border-bottom: 1px solid #E8E8E8;
}

.footer .service ul {
    display: flex;
    justify-content: space-around;
}

.footer .service li {
    display: flex;
    line-height: 58px;
}

.footer .service span {
    display: block;
    margin-right: 20px;
    width: 58px;
    height: 58px;
    background-image: url(~@/assets/images/sprite.png);
}

.footer .service li:nth-child(2) span {
    background-position: 0 -58px;
}

.footer .service li:nth-child(3) span {
    background-position: 0 -116px;
}

.footer .service li:nth-child(4) span {
    background-position: 0 -174px;
}

.footer .service p {
    font-size: 28px;
}

.footer .help {
    display: flex;
    justify-content: space-between;
    margin-top: 60px;
}

.footer .help .left {
    display: flex;
}

.footer .help .left dl {
    margin-right: 84px;
}

.footer .help .left dt {
    margin-bottom: 30px;
    font-size: 18px;
}

.footer .help .left dd {
    margin-bottom: 10px;
}

.footer .help .left dd a {
    color: #969696;
}

.footer .help .right ul {
    display: flex;
    align-items: flex-start;
}

.footer .help .right li:nth-child(1) {
    margin-right: 55px;
    text-align: center;
}

.footer .help .right div {
    margin-bottom: 10px;
    width: 120px;
    height: 120px;
    color: #969696;
}

.icon-customer-service {
    margin-left: 3px;
    color: #00BE9A;
}

.copyright {
    margin-top: 100px;
    text-align: center;
    color: #A1A1A1;
}

.copyright p {
    margin-bottom: 15px;
}

.copyright a {
    margin: 0 10px;
    color: #A1A1A1;
}
style>

感谢大家的阅读,如有不对的地方,可以向我提出,感谢大家!

你可能感兴趣的:(vue.js,javascript,前端)