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 ...
随机推荐
- nginx的location与proxy_pass指令超详细讲解及其有无斜杠( / )结尾的区别
本文所使用的环境信息如下: windows11 (主机系统) virtual-box-7.0环境下的ubuntu-18.04 nginx-1.22.1 (linux) 斜杠结尾之争 实践中,nginx ...
- Selenium-[实例]猫眼电影爬取
import random import time from selenium import webdriver from selenium.webdriver import ActionChains ...
- python获取已安装程序列表
python获取已安装程序列表 本文主要讲述通过python脚本获取android 设备已安装列表. 首先,Python本身无法直接获取Android设备上已安装的程序列表,所以这里主要借助adb命令 ...
- 【李南江】从零玩转TypeScript
前言 老套路肯定是 需要知道TS是干啥用的啦. 1.什么是TypeScript(TS)? TypeScript简称TS TS和JS之间的关系其实就是Less/Sass和CSS之间的关系 就像Less/ ...
- MySQL的事务(看看也许有帮助呢)
MySQL的事务 一.事务的概念 在MySQL中,只有InnoDB存储引擎才支持事务. 事务的处理用来维护数据库数据的完整性,保证同一个事务里的一批SQL语句,要么全部执行,要么全部不执行. 事务用来 ...
- 拓扑排序软件设计——ToplogicalSort_app(含有源码、需求分析、可行性分析、概要设计、用户使用手册)
@ 目录 前言 1. 需求分析 2. 可行性分析 2.1 简介 2.2 技术可行性分析 2.2.1 技术实现方案 2.2.2 开发人员技能要求 2.2.3 可行性 2.3 操作可行性分析 2.4 结论 ...
- <Python全景系列-1> Hello World,1分钟配置好你的python环境
<从此开始:1分钟配置好你的python环境> 欢迎来到我们的系列博客<Python360全景>!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题, ...
- Blazor技术入门
曾写过点儿前后端分离的项目(Vue+.NET Core Web API).WPF和WinForm.因为Blazor不支持小程序的原因(相对于uniapp),所以只是大概知道Blazor可以写Web.P ...
- 云图说|初识数据库和应用迁移UGO
阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要:数据库和应用迁移 ...
- 单日30PB量级!火山引擎ByteHouse云原生的数据导入这么做
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近期,火山引擎ByteHouse技术专家受邀参加DataFunCon2023(深圳站)活动,并以"火 ...