08-Vue(实战TabBar一)

效果图 。先开发底部导航栏
在这里插入图片描述
base样式:

body {
  padding: 0;
  margin: 0;
}

components :
TabBar.vue:

<template>
  <div id="tab-bar">
    <!--  插槽  -->
    <slot></slot>
  </div>
</template>

<script>
import TabBarItem from "./TabBarItem";

export default {
  name: "TabBar",

  components: {
    TabBarItem
  }

}
</script>

<style scoped>
#tab-bar {
  display: flex; /*弹性盒子*/
  background-color: #f6f6f6;

  position: fixed; /*固定定位*/
  left: 0;
  right: 0;
  bottom: 0;

  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.1); /*阴影*/
}

</style>

components :
TabBarItem.vue

<template>
  <div class="tab-bat-item">
    <!--  具名插槽  -->
    <slot name="item-icon"></slot>
    <slot name="item-text"></slot>
  </div>
</template>

<script>
export default {
  name: "TabBarItem"
}
</script>

<style scoped>
.tab-bat-item {
  flex: 1; /*平均分布*/
  text-align: center; /*文字居中*/
  height: 49px; /*导航高度*/
  font-size: 15px;
}

/*图标*/
.tab-bat-item img {
  width: 24px;
  height: 24px;
  margin-top: 3px;
  vertical-align: middle; /*去除图片默认3px边距*/
  margin-bottom: 2px;
}
</style>

App.vue

<template>
  <div id="app">
    <!-- 使用组件   -->
    <tab-bar>
      <tab-bar-item>
        <!--   使用插槽     -->
        <img slot="item-icon" src="./assets/img/tabbar/index.svg" alt="">
        <div slot="item-text">首页</div>
      </tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/classify.svg" alt="">
        <div slot="item-text">分类</div>
      </tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/shoppingCart.svg" alt="">
        <div slot="item-text">购物车</div>
      </tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/my.svg" alt="">
        <div slot="item-text"> 我的</div>
      </tab-bar-item>
    </tab-bar>
  </div>
</template>

<script>
import TabBar from "./components/tabbar/TabBar";
import TabBarItem from "./components/tabbar/TabBarItem";

export default {

  name: 'App',
  components: {
    TabBar,
    TabBarItem
  }
}
</script>


<style>
@import "./assets/css/base.css";


</style>

目录结构
img目录来自阿里巴巴图标库
在这里插入图片描述

状态切换

为了让用户点击时对应的图标以及文字发生变化,现在在TabBarItem组件多加一个插槽,让传过来两个图标,点击时显示这个图标,没有点击时选择另一个图标。
在这里插入图片描述
在这里插入图片描述

目前的样子:
在这里插入图片描述
很明显 ,这不是我们想要的效果,我们要对图片加以判断,什么时候显示哪一张
在这里插入图片描述

页面路由配置

分别创建页面对应的组件
在这里插入图片描述
在这里插入图片描述
监听每一个tabbar ,click时跳到 传过来的路径

在这里插入图片描述
在这里插入图片描述
在使用组件时就需要把path传过来
在这里插入图片描述

动态改变导航选中

在这里插入图片描述

动态文字颜色

如果有传值,就使用传的值,如果没有传 ,就使用默认值
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

路径别名

给复杂的路径起一个别名,不管移动到哪里,都不需要修改路径

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值