vue tabBar导航栏设计实现3-进一步抽取tab-item
系列导航
二、vue tabBar导航栏设计实现2-抽取tab-bar
三、vue tabBar导航栏设计实现3-进一步抽取tab-item
四、vue tabBar导航栏设计实现4-再次抽取MainTabBar
tabBar导航栏设计3-进一步抽取tab-item
一、本节目标效果
抽取一个tab-bar-item组件负责导航栏的布局

二、代码结构

注:主要是标红的几个文件
三、代码
重新编写这几个文件中的代码
App.vue
<template>
<div id="app">
<tab-bar>
<tab-bar-item>
<template v-slot:item-icon>
<img :src="require('./assets/img/tabbar/home.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">首页</div>
</template>
</tab-bar-item>
<tab-bar-item>
<template v-slot:item-icon>
<img :src="require('./assets/img/tabbar/category.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">分类</div>
</template>
</tab-bar-item>
<tab-bar-item>
<template v-slot:item-icon>
<img :src="require('./assets/img/tabbar/shopcart.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">购物车</div>
</template>
</tab-bar-item>
<tab-bar-item>
<template v-slot:item-icon>
<img :src="require('./assets/img/tabbar/profile.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">我的</div>
</template>
</tab-bar-item>
</tab-bar>
</div>
</template> <script>
import {
defineComponent
} from 'vue'
import TabBar from './components/tabbar/TabBar'
import TabBarItem from './components/tabbar/TabBarItem'
export default defineComponent({
//组件名称
name: 'App',
//接收父组件的数据
props: {},
components: {
TabBar,
TabBarItem
},
setup(props, ctx) {
return {}
}
})
</script> <style lang="scss">
@import "./assets/css/base.css";
</style>
TabBar.vue
<template>
<div id="tab-bar">
<slot></slot>
</div>
</template> <script> import {defineComponent} from 'vue' export default defineComponent({
//组件名称
name:'TabBar',
//接收父组件的数据
props:{
},
components: { },
setup(props,ctx){
return{
}
}
}) </script> <style lang="scss">
#tab-bar {
display: flex;
background-color: #f6f6f6; position: fixed;
left: 0;
right: 0;
bottom: 0; box-shadow: 0 -1px 1px rgba(100,100,100,.2);
} </style>
TabBarItem.vue
<template>
<div class="tab-bar-item">
<slot name="item-icon"></slot>
<slot name="item-text"></slot>
</div>
</template> <script> import {defineComponent} from 'vue' export default defineComponent({
//组件名称
name:'TabBarItem',
//接收父组件的数据
props:{
},
components: { },
setup(props,ctx){
return{
}
}
})
</script> <style lang="scss">
.tab-bar-item {
flex: 1;
text-align: center;
height: 49px;
font-size: 14px;
} .tab-bar-item img {
width: 24px;
height: 24px;
margin-top: 3px;
vertical-align: middle;
margin-bottom: 2px;
}
</style>
base.css
body {
padding: 0;
margin: 0;
}
一些图片
四、代码按照步骤解释
1、抽取TabBarItem组件,利用插槽使该组件独立


2、数据放到App.vue 注:具体看源码 引入TabBar和TabBarItem两个组件

vue tabBar导航栏设计实现3-进一步抽取tab-item的更多相关文章
- 微信小程序------导航栏样式、tabBar导航栏
一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { "pages":[ " ...
- 微信小程序入门四: 导航栏样式、tabBar导航栏
实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { & ...
- 超详细Vue实现导航栏绑定内容锚点+滚动动画+vue-router(hash模式可用)
超详细Vue实现导航栏绑定内容锚点+滚动动画+vue-router(hash模式可用) 转载自:https://www.jianshu.com/p/2ad8c8b5bf75 亲测有效~ <tem ...
- Nuxt/Vue自定义导航栏Topbar+标签栏Tabbar组件
基于Vue.js实现自定义Topbar+Tabbar组件|仿咸鱼底部凸起导航 最近一直在倒腾Nuxt项目,由于Nuxt.js是基于Vue.js的服务端渲染框架,只要是会vue,基本能很快上手了. 一般 ...
- 使用vue给导航栏添加链接
如下面的导航栏,使用vue技术给该导航栏增加链接: js代码为: navigation:function(){ new Vue({ el: '#navUl', data: { menuData:{ ' ...
- Flutter - TabBar导航栏切换后,状态丢失
上一篇讲到了 Flutter - BottomNavigationBar底部导航栏切换后,状态丢失 里面提到了TabBar,这儿专门再写一下吧,具体怎么操作,来不让TabBar的状态丢失.毕竟大家99 ...
- 记一次Vue跨导航栏问题解决方案
简述 这篇文章是我项目中,遇到的一个issue,我将解决过程和方法记录下来. 本篇文章基于Vue.js进行的前端页面构建,由于仅涉及前端,将不做数据来源及其他部分的叙述.使用的CSS框架是 Boots ...
- Vue设置导航栏为公共模块并在登录页不显示
1.公共模块的内容可以放在App.vue中但是通常登录页面是不需要导航的,那么就需要规避登录页这时,就可以采用keep-alive结合$route.meta来实现这个功能.keep-alive 是 V ...
- vue 侧边导航栏递归显示
import axios from "axios"; import tabs1 from "../tab_content/tab1.vue"; import m ...
- 新浪微博客户端(1)-实现Tabbar导航栏效果
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
随机推荐
- 231106-jmeter随笔
1. 获取接口的执行时间 String ctime = prev.getTime().toString();2. String转int int c = Integer.parseInt(ctime); ...
- 使用Slurm集群进行分布式图计算:对Github网络影响力的系统分析
本文分享自华为云社区<基于Slurm集群的分布式图计算应用实践:Github协作网络影响力分析>,作者:yd_263841138 . 1. 引言 Slurm(Simple Linux Ut ...
- JOISC2017 题解
\(\text{By DaiRuiChen 007}\) Contest Link A. Cultivation Problem Link 题目大意 在一个 \(r\times c\) 的网格上有 \ ...
- [ABC263E] Sugoroku 3
Problem Statement There are $N$ squares called Square $1$ though Square $N$. You start on Square $1$ ...
- spring报错-Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 63
这个错误原因是因为JDK版本过高,改一下版本就行了 把里面的19改成8 这样就行了
- KNN算法实战——海伦约会(KDtree优化)
本文通过海伦约会的例子来测试之前写的KDTree的效果,并且探讨了特征是否进行归一化对整个模型的表现的影响.最后发现在机器学习中,特征归一化确实对模型能提供非常大的帮助. 1 from KDTree ...
- Kernel Memory 入门系列:快速开始
Kernel Memory 入门:Quick Start 了解了用户问答和文档预处理的流程之后,我们就可以直接开始使用Kernel Memory了. 1. 安装 项目中只需要通过NuGet安装Micr ...
- CAP 8.0 版本发布通告 - CAP 7岁生日快乐!
前言 今天,我们很高兴宣布 CAP 发布 8.0 版本正式版,从 2016 年 12 月 14 日CAP立项到 2023 年 12 月14 日发布 8.0 版本刚好满 7 年,祝 CAP 7 岁生日快 ...
- C++ Qt开发:StandardItemModel数据模型组件
Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍Standar ...
- Selenium-ActionChains动作链(针对鼠标、滚轮等操作
https://www.selenium.dev/documentation/webdriver/actions_api/ 注意:对于滚轮的操作,只支持chrome浏览器,且selenium版本在4. ...