转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_1.html

项目github地址:https://github.com/shamoyuu/vue-vux-iconan

继续上一篇文章,这次以实际项目为主题。

我们做一个看漫画的APP,名字就叫爱柯南,但是不会只有柯南一个。

首先在components下新建main文件夹,用来存放4个主导航页。

在这个文件夹下新建4个vue文件,分别是Home.vue、News.vue、Classify.vue、Personal.vue,内容都一样

<template>
<div>
<h1>{{msg}}</h1>
<img src="@/static/images/logo.png">
</div>
</template> <script>
export default {
data () {
return {
msg: "首页" //把这里都改一下
}
}
}
</script> <style scoped> </style>

@这里可以简单地理解为src根路径。

然后修改tool/router/index.js文件

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/main/Home'
import News from '@/components/main/News'
import Classify from '@/components/main/Classify'
import Personal from '@/components/main/Personal' Vue.use(Router); export default new Router({
routes: [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'home',
component: Home
},
{
path: '/news',
name: 'news',
component: News
},
{
path: '/classify',
name: 'classify',
component: Classify
},
{
path: '/personal',
name: 'personal',
component: Personal
}
]
});

然后在components下新建Footer.vue文件,用来处理底部导航

<template>
<tabbar @on-index-change="foo">
<tabbar-item selected>
<img slot="icon" src="../assets/images/homepage.png">
<img slot="icon-active" src="../assets/images/homepage_fill.png">
<span slot="label">首页</span>
</tabbar-item>
<tabbar-item>
<img slot="icon" src="../assets/images/flashlight.png">
<img slot="icon-active" src="../assets/images/flashlight_fill.png">
<span slot="label">最新</span>
</tabbar-item>
<tabbar-item>
<img slot="icon" src="../assets/images/createtask.png">
<img slot="icon-active" src="../assets/images/createtask_fill.png">
<span slot="label">分类</span>
</tabbar-item>
<tabbar-item>
<img slot="icon" src="../assets/images/people.png">
<img slot="icon-active" src="../assets/images/people_fill.png">
<span slot="label">我的</span>
</tabbar-item>
</tabbar>
</template> <script>
import {Tabbar, TabbarItem} from 'vux'
import router from '@/tool/router/index.js' export default {
name: 'AppFooter',
components: {
Tabbar,
TabbarItem
},
methods: {
foo: function (newindex, oldindex) {
switch (newindex){
case :
router.replace('/home');
break;
case :
router.replace('/news');
break;
case :
router.replace('/classify');
break;
case :
router.replace('/personal');
break;
}
}
}
}
</script>
<style> </style>

需要注意的是,我们这里并不采用vux官方API里demo的跳转方式(在TabbarItem上加link),而是用on-index-change事件,在这个事件里我们通过router.replace来切换路由,否则你在多次点击底部导航之后再回退的话,会把前面点过的再回退一遍。

我们再添加几个less样式,来初始化和添加全局样式。

在assets下新建less文件夹,在里面新建

app.less

#app {
.weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon,
.weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon > i,
.weui-tabbar__item.weui-bar__item_on .weui-tabbar__label {
color: #1296DB
}
}

reset.less

button {
-webkit-tap-highlight-color: rgba(, , , );
-webkit-appearance: none;
padding: ;
margin: ;
outline: none;
border: none;
border-radius: ;
background: transparent;
}

main.less

@import '~vux/src/styles/reset.less';
@import "reset";
@import "app";

然后修改APP.vue文件

<template>
<div id="app">
<router-view/>
<app-footer></app-footer>
</div>
</template> <script>
import AppFooter from './components/Footer.vue' export default {
name: 'app',
components: {
AppFooter
}
}
</script> <style lang="less">
@import "./assets/less/main.less";
</style>

上面用到的几个图片,可以直接到github里下载。

【前端】Vue2全家桶案例《看漫画》之一、添加四个导航页的更多相关文章

  1. 【前端】Vue2全家桶案例《看漫画》之番外篇、express上传漫画(可选)

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_extra_1.html 项目github地址:https://github.com/sha ...

  2. 【前端】Vue2全家桶案例《看漫画》之六、图片阅读页

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_6.html 项目github地址:https://github.com/shamoyuu/ ...

  3. 【前端】Vue2全家桶案例《看漫画》之四、漫画页

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_4.html 项目github地址:https://github.com/shamoyuu/ ...

  4. 【前端】Vue2全家桶案例《看漫画》之二、完成首页基本样式

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_2.html 项目github地址:https://github.com/shamoyuu/ ...

  5. 【前端】Vue2全家桶案例《看漫画》之七、webpack插件开发——自动替换服务器API-URL

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_7.html 项目github地址:https://github.com/shamoyuu/ ...

  6. 【前端】Vue2全家桶案例《看漫画》之五、引入axios

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_5.html 项目github地址:https://github.com/shamoyuu/ ...

  7. 【前端】Vue2全家桶案例《看漫画》之三、引入vuex

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_3.html 项目github地址:https://github.com/shamoyuu/ ...

  8. Vue2全家桶+Element搭建的PC端在线音乐网站

    目录 1,前言 2,已有功能 3,使用 4,目录结构 5,页面效果 登录页 首页 排行榜 歌单列表 歌单详情 歌手列表 歌手详情 MV列表 MV详情 搜索页 播放器 1,前言 项目基于Vue2全家桶及 ...

  9. Vue2全家桶之一:vue-cli(vue脚手架)超详细教程

    本文转载于:https://www.jianshu.com/p/32beaca25c0d   都说Vue2简单上手容易,的确,看了官方文档确实觉得上手很快,除了ES6语法和webpack的配置让你感到 ...

随机推荐

  1. 【转】awk 数组用法【精华贴】

    文本处理的工作中,awk的数组是必不可少的工具,在这里,同样以总结经验和教训的方式和大家分享下我的一些学习心得,如有错误的地方,请大家指正和补充. awk的数组,一种关联数组(Associative ...

  2. MySQL相关命令与备份

    不加任何参数直接备份 mysqldump -uroot zabbix >/opt/zabbix.bak.sql 恢复,这样恢复时需要自已创建表 mysql -uroot < zabbix. ...

  3. 【转】GLONASS全球卫星导航系统

    GLONASS是“GLOBAL NAVIGATION SATELLITE SYSTE(全球卫星导航系统)”的缩写,作用类似于美国的GPS.欧洲的伽利略卫星定位系统.最早开发于苏联时期,后由俄罗斯继续该 ...

  4. JavaSE基础篇—MySQL基础知识点

    MySQL MySQL是一种关系数据库管理系统,是一种开源软件.可搭配PHP和Apache可以有更好的性能,也可以工作在众多的平台上.Orcale是一个数据库创建多个用户,MySQL是一个用户创建多个 ...

  5. 蓝桥杯练习系统— 算法训练 Beaver's Calculator

    问题描述 从万能词典来的聪明的海狸已经使我们惊讶了一次.他开发了一种新的计算器,他将此命名为"Beaver's Calculator 1.0".它非常特别,并且被计划使用在各种各样 ...

  6. jmeter用Firefox录制https协议证书问题解决

    录制脚本的时候,比如录制https协议的百度网站 https://www.baidu.com ,所有录制设置均正常,但是在jmeter录制控制器里面就是没有任何录制的请求. 这个时候提示说证书不对 1 ...

  7. Sonar 数据库表关系整理一(rule相关)

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/7510072.html 简介:Sonar ...

  8. Spring整合JMS(四)——事务管理

    原文链接:http://haohaoxuexi.iteye.com/blog/1983532 Spring提供了一个JmsTransactionManager用于对JMS ConnectionFact ...

  9. 【非原创】C++类成员函数的重载、覆盖和隐藏

    链接:https://www.nowcoder.com/questionTerminal/266d3a6d4f1b436aabf1eff3156fed95来源:牛客网 题目:类成员函数的重载.覆盖和隐 ...

  10. php 数组变成树状型结构

    <? php $stime = microtime(true); $nodes = [ ['id' = > 1, 'pid' = > 0, 'name' = > 'a'], [ ...