系列导航

一、vue tabBar导航栏设计实现1-初步设计

二、vue tabBar导航栏设计实现2-抽取tab-bar

三、vue tabBar导航栏设计实现3-进一步抽取tab-item

四、vue tabBar导航栏设计实现4-再次抽取MainTabBar

五、vue tabBar导航栏设计实现5-最终版本

tabBar导航栏设计4-再次抽取MainTabBar

一、     本节目标效果

上一个节的例子中App.vue中代码量还是很大如何简化App.vue,再次抽取一个MainTabBar组件负责在TabBarItem里放数据

二、代码结构

注:主要是标红的几个文件

三、代码

App.vue

<template>
<div id="listStyle" >
<div id="dayCount">
今日点击:99999 | 今日发布:2000 | 今日下载:1000
</div>
<List border header="资源信息" size="large" >
<ListItem v-for="(item, index) in resourcesList">
<ListItemMeta :avatar="getImgUrl(item.iconPath)" :title="item.title" :description="item.resourcesDesc" />
<template slot="action">
<li>
<Icon type="ios-star-outline" /> {{item.perfectTimes}}
</li>
<li>
<Icon type="ios-thumbs-up-outline" />{{item.goodTimes}}
</li>
<li>
<Icon type="ios-chatbubbles-outline" /> {{item.badTimes}}
</li>
</template>
</ListItem>
<Page id="page" :total="pageTotal" :current="pageNum" :page-size="pageSize" @on-change="handlePage" show-total show-elevator next-text="下一页"/>
</list> </div>
</template> <script>
import {getXyResourcesInfoV} from '@/network/index.js'; //分页的初始参数
const paramter = {
page: 1,
pagesize:4,
ispage:'Y'
}; export default {
name: "MainList",
props: { },
data() { return {
resourcesList: [] ,
pageTotal: 0,
pageNum: 1,
pageSize: 10,
}
},
created() {
this.dataListInit(); },
computed: { },
methods: {
//页面变更
handlePage(value) {
console.log('value:'+value);
this.pageNum = value;
paramter.page = value; this.dataListInit()
}, dataListInit() {
getXyResourcesInfoV(paramter).then(res => {
//debugger
this.pageTotal = res.data.page.count;
this.pageSize = res.data.page.pagesize;
this.pageNum = res.data.page.page;
this.resourcesList = [];
for (var i = 0; i < res.data.obj.dataList.length; i++) {
this.resourcesList.push({
resourcesId: res.data.obj.dataList[i].resourcesId,
title: res.data.obj.dataList[i].title,
resourcesDesc:res.data.obj.dataList[i].resourcesDesc,
perfectTimes:res.data.obj.dataList[i].perfectTimes,
goodTimes:res.data.obj.dataList[i].goodTimes,
badTimes:res.data.obj.dataList[i].badTimes,
iconPath:res.data.obj.dataList[i].iconPath
})
} })
.catch(error => {}); }, itemClick() {
this.$router.replace(this.path)
}, // 动态获取头像图片
getImgUrl(picName) {
//默认图标
//debugger if( picName == 'init' ){
return require("@/assets/image/element/headPhoto/1.png");
}else{
//base64图标
return picName;
}
} }
}
</script> <style lang="scss">
#dayCount { height: 30px; //设置高度
font-size: 15px; //设置字体大小
color: #2d8cf0;
// position: relative;
font-family: "PingFang SC";
padding: 7px
} #page{
//float:right
text-align:right
} </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>

MainTabBar.vue

<template>
<tab-bar>
<tab-bar-item path="/">
<template v-slot:item-icon>
<img :src="require('../../assets/img/tabbar/home.svg')">
</template>
<template v-slot:item-icon-active>
<img :src="require('../../assets/img/tabbar/home_active.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">首页</div>
</template>
</tab-bar-item>
<tab-bar-item path="/category">
<template v-slot:item-icon>
<img :src="require('../../assets/img/tabbar/category.svg')">
</template>
<template v-slot:item-icon-active>
<img :src="require('../../assets/img/tabbar/category_active.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">分类</div>
</template>
</tab-bar-item>
<tab-bar-item path="/cart">
<template v-slot:item-icon>
<img :src="require('../../assets/img/tabbar/shopcart.svg')">
</template>
<template v-slot:item-icon-active>
<img :src="require('../../assets/img/tabbar/shopcart_active.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">购物车</div>
</template>
</tab-bar-item>
<tab-bar-item path="/profile">
<template v-slot:item-icon>
<img :src="require('../../assets/img/tabbar/profile.svg')">
</template>
<template v-slot:item-icon-active>
<img :src="require('../../assets/img/tabbar/profile_active.svg')">
</template>
<template v-slot:item-text>
<div slot="item-text">我的</div>
</template>
</tab-bar-item>
</tab-bar>
</template> <script>
import TabBar from '../tabbar/TabBar'
import TabBarItem from '../tabbar/TabBarItem' export default {
name: "MainTabBar",
components: {
TabBar,
TabBarItem
}
}
</script> <style scoped> </style>

index.js

import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Category from '../views/Category.vue'
import Cart from '../views/Cart.vue'
import Profile from '../views/Profile.vue' const routes = [
{
path: '/',
name: 'Home',
component: Home
} ,
{
path: '/category',
component: Category
},
{
path: '/cart',
component: Cart
},
{
path: '/profile',
component: Profile
}
] const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
}) export default router

其他一些代码不很简单看之前的博客内容

四、代码按照步骤解释

1、 抽取MainTabBar.vue组件

MainTabBar.vue组件里调用TabBar.vue和TabBarItem.vue组件,并且将数据放到MainTabBar.vue组件里。

2、TabBarItem.vue组件里增加itemClick方法负责页面跳转 ,跳转的地址由MainTabBar.vu中的tab-bar-item 组件的path属性动态传递过来。

3、 index.js中配置路由

4、App.vue中调用MainTabBar.vue组件,注意这里一定要加一个<router-view>标签要不路径跳转没有占位符就不会有效果。

vue tabBar导航栏设计实现4-再次抽取MainTabBar的更多相关文章

  1. 微信小程序------导航栏样式、tabBar导航栏

    一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { "pages":[ " ...

  2. 微信小程序入门四: 导航栏样式、tabBar导航栏

    实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { & ...

  3. 超详细Vue实现导航栏绑定内容锚点+滚动动画+vue-router(hash模式可用)

    超详细Vue实现导航栏绑定内容锚点+滚动动画+vue-router(hash模式可用) 转载自:https://www.jianshu.com/p/2ad8c8b5bf75 亲测有效~ <tem ...

  4. Nuxt/Vue自定义导航栏Topbar+标签栏Tabbar组件

    基于Vue.js实现自定义Topbar+Tabbar组件|仿咸鱼底部凸起导航 最近一直在倒腾Nuxt项目,由于Nuxt.js是基于Vue.js的服务端渲染框架,只要是会vue,基本能很快上手了. 一般 ...

  5. 使用vue给导航栏添加链接

    如下面的导航栏,使用vue技术给该导航栏增加链接: js代码为: navigation:function(){ new Vue({ el: '#navUl', data: { menuData:{ ' ...

  6. Flutter - TabBar导航栏切换后,状态丢失

    上一篇讲到了 Flutter - BottomNavigationBar底部导航栏切换后,状态丢失 里面提到了TabBar,这儿专门再写一下吧,具体怎么操作,来不让TabBar的状态丢失.毕竟大家99 ...

  7. 记一次Vue跨导航栏问题解决方案

    简述 这篇文章是我项目中,遇到的一个issue,我将解决过程和方法记录下来. 本篇文章基于Vue.js进行的前端页面构建,由于仅涉及前端,将不做数据来源及其他部分的叙述.使用的CSS框架是 Boots ...

  8. Vue设置导航栏为公共模块并在登录页不显示

    1.公共模块的内容可以放在App.vue中但是通常登录页面是不需要导航的,那么就需要规避登录页这时,就可以采用keep-alive结合$route.meta来实现这个功能.keep-alive 是 V ...

  9. vue 侧边导航栏递归显示

    import axios from "axios"; import tabs1 from "../tab_content/tab1.vue"; import m ...

  10. 新浪微博客户端(1)-实现Tabbar导航栏效果

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

随机推荐

  1. VS Code安装教程

    一.下载 1.官网 下载地址:https://code.visualstudio.com/Download 2.下载 根据自己电脑型号下载,此处以Windows为例. 二.安装 1.下载完成后,直接点 ...

  2. 看看 Asp.net core Webapi 项目如何优雅地使用分布式缓存

    前言 缓存是提升程序性能必不可少的方法,Asp.net core 支持多级缓存配置,主要有客户端缓存.服务器端缓存,内存缓存和分布式缓存等.其中客户端缓和服务器端缓存在使用上都有比较大的限制,而内存缓 ...

  3. 解密数据可视化软件、BI软件和数字孪生软件的不同

    在现代企业和科技领域,数据起着至关重要的作用.为了更好地管理和理解数据,不同类型的软件工具应运而生,其中包括数据可视化软件.BI(Business Intelligence)软件和数字孪生软件.虽然它 ...

  4. Calico IPIP模式下的Cross Subnet特性分析

    本文分享自华为云社区<Calico IPIP模式下的CrossSubnet特性分析>,作者: 可以交个朋友. Calico ipip crossSubnet 模式 Calico-ipip模 ...

  5. Net 高级调试之十五:经典的锁故障

    一.简介 今天是<Net 高级调试>的第十五篇文章,这个系列的文章也快结束了,但是我们深入学习的脚步还不能停止.上一篇文件我们介绍了C# 中一些锁的实现逻辑,并做到了眼见为实的演示给大家它 ...

  6. loader编写小记

    此项目在一些大佬的基础上进行了修改,或许能提供一些思路.还在学习中很菜很菜,不足之处还请师傅们多多指点 tips 对shellcode使用AES + Base85加密后以txt保存在远端供下载. 针对 ...

  7. Python——第五章:time模块、datetime模块

    time模块 在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime,calendar(很少用,不讲),下面分别来介绍. 我们写程序时对时间 ...

  8. intel 虚拟化 VT-d VT-x VT-c 的区别

    intel 虚拟化 VT-d VT-x VT-c 有什么区别,各是什么意思,有什么作用 简单描述理解 VT-d VT-x VT-c VT-d 英文全程为 Virtualization Technolo ...

  9. MySQL运维实战(1.2)安装部署:使用二进制安装部署

    作者:俊达 引言 上一篇我们使用了RPM进行安装部署,这是一种安装快速.简化部署和管理过程.与操作系统提供的包管理工具紧密集成的部署方法.此外,当你需要更高的灵活性和自定义性,并且愿意承担一些额外的手 ...

  10. Java的特性、内容和环境的配置

    Java的特性和优势 简单性 面向对象 可移植性 高性能 分布式 动态性 多线程 安全性 健壮性 JDK包含JRE包含JVM JDK:Java Development Kit JRE:Java Run ...