使用vue2.0写移动端的时候,经常会写底部导航效果,点击切换路由效果,实现图片和文字颜色切换。vue2.0也提供了很多ul框架供我们实现效果,今天就用原生的实现一个底部导航切换,直接上代码:

效果图

路由搭建

export default new Router({
routes: [
{
path: "/Home",
component: Home,
},
{
path: "/recommend",
component: Recommend
},
{
path: "/search",
component: Search
},
{
path: "/chat",
component: Chat
},
{
path: "/me",
component: Me
},
  {
path: '/',
redirect: '/home'
},
]
});

 页面模板搭建,src和on都要动态的绑定,使用三目运算判断每次点击切换

<div class="bottom-tab">
<div class="tab-item" @click="switchTo('/home')">
<img :src="'/home' === $route.path ? tabBarImgArr[0].selected : tabBarImgArr[0].normal" alt="首页">
<span :class="{on: '/home' === $route.path}">首页</span>
</div>
<div class="tab-item" @click="switchTo('/recommend')">
<img :src="'/recommend' === $route.path ? tabBarImgArr[1].selected : tabBarImgArr[1].normal" alt="推荐">
<span :class="{on: '/recommend' === $route.path}">推荐</span>
</div>
<div class="tab-item" @click="switchTo('/search')">
<img :src="'/search' === $route.path ? tabBarImgArr[2].selected : tabBarImgArr[2].normal" alt="搜索">
<span :class="{on: '/search' === $route.path}">搜索</span>
</div>
<div class="tab-item" @click="switchTo('/chat')">
<img :src="'/chat' === $route.path ? tabBarImgArr[3].selected : tabBarImgArr[3].normal" alt="聊天">
<span :class="{on: '/chat' === $route.path}">聊天</span>
</div>
<div class="tab-item" @click="switchTo('/me')">
<img :src="'/me' === $route.path ? tabBarImgArr[4].selected : tabBarImgArr[4].normal" alt="我的">
<span :class="{on: '/me' === $route.path}">我的</span>
</div>
</div>

  在data里面定义tabBarImgArr:数组,用于存放图片。

tabBarImgArr:[   //图片切换
{normal: require('./../../../static/img/icon_home.png'), selected: require('./../../../static/img/icon_home_selected.png')},
{normal: require('./../../../static/img/icon_intro.png'), selected: require('./../../../static/img/icon_intro_selected.png')},
{normal: require('./../../../static/img/icon_search.png'), selected: require('./../../../static/img/icon_search_selected.png')},
{normal: require('./../../../static/img/icon_chat.png'), selected: require('./../../../static/img/icon_chat_selected.png')},
{normal: require('./../../../static/img/icon_mine.png'), selected: require('./../../../static/img/icon_mine_selected.png')}
]

 在methods实现switchTo切换

methods:{
switchTo(path){
// console.log(this.$router)
this.$router.replace(path)
}
}

css样式效果

.bottom-tab
width %
height 50px
background-color #fff
position fixed
left 0px
bottom 0px
display flex
z-index
.tab-item
display flex
flex
flex-direction column
align-items center
justify-content center
font-size 14px
color #
img
width %
margin-bottom 2px
.on
color red

vue2.0实现底部导航切换效果的更多相关文章

  1. MUI底部导航切换子页面

    1.登陆页面进入之后,进入到main页面,main页面只有一个底部导航,然后引入子页面进行渲染. <nav class="mui-bar mui-bar-tab" id=&q ...

  2. 微信小程序~TabBar底部导航切换栏

    底部导航栏这个功能是非常常见的一个功能,基本上一个完成的app,都会存在一个导航栏,那么微信小程序的导航栏该怎么实现呢?经过无数的踩坑,终于实现了,好了,先看看效果图. 对于底部导航栏,小程序上给出的 ...

  3. Fragment实现底部选项卡切换效果

    现在很多APP的样式都是底部选项卡做为首页的,实现这样的效果,我们一般有这样几种方式,第一,最屌丝的做法,我直接自定义选项卡视图,通过监听选项卡视图,逻辑控制内容页的切换,这样做的想法一般是反正这几个 ...

  4. Mui 底部导航切换

    1.建好子模板目录 2.导航代码 <nav class="mui-bar mui-bar-tab"> <a id="defaultTab" c ...

  5. MUI底部导航栏切换效果

    首先是html代码: <nav class="mui-bar mui-bar-tab"> <a href="view/templates/home/ho ...

  6. mui底部导航栏切换分页

    使用Hbuilder的mui框架开发移动端非常便利.高效: 底部导航栏切换功能也是移动APP开发中必须实现的: 引入mui文件.下面会用到jquery,同时引进 <link href=" ...

  7. 二、Fragment+RadioButton实现底部导航栏

    在App中经常看到这样的tab底部导航栏   那么这种效果是如何实现,实现的方式有很多种,最常见的就是使用Fragment+RadioButton去实现.下面我们来写一个例子 首先我们先在activi ...

  8. Android商城开发系列(三)——使用Fragment+RadioButton实现商城底部导航栏

    在商城第一篇的开篇当中,我们看到商城的效果图里面有一个底部导航栏效果,如下图所示: 今天我们就来实现商城底部导航栏,最终效果图如下所示:   那么这种效果是如何实现,实现的方式有很多种,最常见的就是使 ...

  9. mui底部选项卡切换实现

    MUI提供了两种webview和div模式,来实现底部选项卡切换 效果相同,div是在同一个页面实现所有切换块的页面,根据id导航,而webview是由多个页面组成,形成页面之间的来回跳转

随机推荐

  1. oracle 游标实现多重循环

    declare -- Local variables here i integer; cursor c_province is select ds.swjg_dm from dm_swjg ds wh ...

  2. Win(Phone)10开发第(2)弹,导出APPX包并签名部署

    当我们新建一个win10 uap项目,如果想导出测试包,需要点击项目名称,选择商店-导出应用包,这个时候会生成一个文件夹,包含appx和ps1等文件. powershell运行Add-AppDevPa ...

  3. 如何把OpenWrt安装到PC?

    前言 什么是openwrt? 它是一个适用于路由器的Linux发行版.和其他Linux发行版一样,它也内置了包管理工具,你可以从一个软件仓库里直接安装软件.OpenWrt可以用在所有需要嵌入式Linu ...

  4. 世界线(bzoj2894)(广义后缀自动机)

    由于春希对于第二世代操作的不熟练,所以刚使用完\(invasion process\)便掉落到了世界线之外,错综复杂的平行世界信息涌入到春希的意识中.春希明白了事件的真相. 在一个冬马与雪菜同时存在的 ...

  5. RabbitMQ实现的RPC

    1.主要思路 1.生产者发布任务时,指定properties,告知消费者处理任务完毕之后,将结果存储到reply_to指定的Queue中,本次任务的id是correlation_id 2.消费者消费完 ...

  6. uiautomator2 手工翻译版

    原文:https://github.com/openatx/uiautomator2 1.安装 pip install --pre uiautomator2   #或者你可以直接从github源码安装 ...

  7. FastAdmin 前端页面传参

    如果我们需要自己在控制器中透传数据到JS中去,则可以使用控制器的assignconfig方法来透传,使用如下 $this->assignconfig('demo', ['name'=>'名 ...

  8. Geometry-587. Erect the Fence

    There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden ...

  9. Windows搭建Nexus3私服

    1. Nexus 简介 Nexus 是一个强大的 Maven 仓库管理器 , 它极大地简化了自己内部仓库的维护和外部仓库的访问 ; 利用 Nexus 你可以只在一个地方就能够完全控制访问和部署在你所维 ...

  10. 解决spring的java.lang.IllegalArgumentException异常

    解决办法是: 右击项目 ---> properties --->project facets : 修改JDK版本,需要将1.8 降为1.7版本.