【前端】Vue2全家桶案例《看漫画》之一、添加四个导航页
转载请注明出处: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全家桶案例《看漫画》之一、添加四个导航页的更多相关文章
- 【前端】Vue2全家桶案例《看漫画》之番外篇、express上传漫画(可选)
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_extra_1.html 项目github地址:https://github.com/sha ...
- 【前端】Vue2全家桶案例《看漫画》之六、图片阅读页
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_6.html 项目github地址:https://github.com/shamoyuu/ ...
- 【前端】Vue2全家桶案例《看漫画》之四、漫画页
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_4.html 项目github地址:https://github.com/shamoyuu/ ...
- 【前端】Vue2全家桶案例《看漫画》之二、完成首页基本样式
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_2.html 项目github地址:https://github.com/shamoyuu/ ...
- 【前端】Vue2全家桶案例《看漫画》之七、webpack插件开发——自动替换服务器API-URL
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_7.html 项目github地址:https://github.com/shamoyuu/ ...
- 【前端】Vue2全家桶案例《看漫画》之五、引入axios
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_5.html 项目github地址:https://github.com/shamoyuu/ ...
- 【前端】Vue2全家桶案例《看漫画》之三、引入vuex
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_app_3.html 项目github地址:https://github.com/shamoyuu/ ...
- Vue2全家桶+Element搭建的PC端在线音乐网站
目录 1,前言 2,已有功能 3,使用 4,目录结构 5,页面效果 登录页 首页 排行榜 歌单列表 歌单详情 歌手列表 歌手详情 MV列表 MV详情 搜索页 播放器 1,前言 项目基于Vue2全家桶及 ...
- Vue2全家桶之一:vue-cli(vue脚手架)超详细教程
本文转载于:https://www.jianshu.com/p/32beaca25c0d 都说Vue2简单上手容易,的确,看了官方文档确实觉得上手很快,除了ES6语法和webpack的配置让你感到 ...
随机推荐
- 【转】shell学习笔记(三)——引用变量、内部变量、条件测试、字符串比较、整数比较等
1.env显示当前的环境变量 2.PS1='[\u@\h \w \A] \$' 可以设置bash的命令与提示符. 3.echo $$ 显示当前bash的PID号 4.echo $?显示上一条指令的回传 ...
- CSS——类和ID选择器的区别
1.相同点,可以应用在任何元素. 2.不同点,ID选择器只能在元素里只能分别引用,不能同时引用. 如: <style type="text/css">.stress{( ...
- 《.NET 设计规范》第 8 章:使用规范
第 8 章:使用规范 8.1 数组 要在公共 API 中优先使用集合,避免使用数组. 不要使用只读的数组字段.虽然字段本身是只读的,用户不能修改它们,但用户可以修改数组中的元素. 考虑使用不规则数组, ...
- python之闭包与装饰器
python闭包与装饰器 闭包 在函数内部定义的函数包含对外部的作用域,而不是全局作用域名字的引用,这样的函数叫做闭包函数. 示例: #-------------------------------- ...
- Facebook发布React 16 专利条款改为MIT开源协议
9 月 26 日,用于构建 UI 的 JavaScript 库 React 16 的最新版本上线. Facebook 最终在现有的两种 React 版本中选择了出现 bug 概率最少的一款.这次版本更 ...
- 微信小程序开发《一》:阿里云tomcat免费配置https
小狼咕咕最近开启了微信小程序开发的征程,由于微信小程序的前后台通信必须通过https协议,所以小狼咕咕第一件要做的事就是配置一个能够通过https访问的后台服务.小狼咕咕用的是阿里云ECS服务器,Li ...
- 实时滚动图表绘制方法: LightningChart教程 + 源码下载
LightningChart图形控件彻底发挥了GPU加速和性能优化的最大效应,能够实时呈现超过10亿数据点的庞大数据,为大家提供先进与快速的图表库.这里的实时图实现的比较简单,大家先试一下这个效果,熟 ...
- srand()和rand()函数的使用
rand()函数不接受参数,默认以1为种子(即起始值). 随机数生成器总是以相同的种子开始,所以形成的伪随机数列也相同,失去了随机意义.(但这样便于程序调试) srand()函数就是指明种子的大小:只 ...
- phpstudy 版本切换注意的问题
如果你也在使用phpstudy的话要注意,因为切换版本后,虽然你的phpinfo 但是实际环境用的是系统环境变量 所以你要去改变下环境变量路径,然后重启电脑. 这样你的版本就是你想切换的版本啦!
- WebSocket就是这么简单
前言 今天在慕课网上看到了Java的新教程(Netty入门之WebSocket初体验):https://www.imooc.com/learn/941 WebSocket我是听得很多,没有真正使用过的 ...