vue导航和首页轮播图实现
来源:互联网 发布:2017流行网络歌曲500首 编辑:程序博客网 时间:2024/06/06 01:21
vue-tabbar vue-slider
1.路由结构图 index.js
使用路由首先要引入Vue-router并use,并将配置好路由的vue-router实例挂载到new出来的Vue实例上,不过vue-cli已将帮我们配置好了,只需要在其基础上继续开发就行
export default new Router({ routes: [ { path:'/', redirect:'/home' }, { path: '/home', component: Home }, { path: '/doctor', component: Doctor }, { path: '/family', component: Family }, { path: '/my', component: My } ]})
- redirect重定向,当路由为空时,会重定向到/home。
2.App.vue
<template> <div> <router-view></router-view> <kk-tabbar></kk-tabbar> </div></template><script> import kkTabbar from './components/Tabbar/ktabbar.vue' export default { components:{ kkTabbar } }</script><style></style>
3.ktabbar.vue
导航组件是一个固定在底部的列表,每个列表都写好了对应的路由,点击每一个就会切换对应的页面。如果路由层级比较深,写起来可能会很长,如to=”test1/test2/test3” ,考虑在配置路由的js中,给每个路由添加name。这样,在router-link中就只需要传递对应的name就可以。
<template> <div class="nav" v-model="select"> <router-link tag="div" class="tab-item" to="/home"> <div class="tab-icon home"></div> <span class="tab-link">首页</span> </router-link> <router-link tag="div" class="tab-item" to="/doctor"> <div class="tab-icon doctor"></div> <span class="tab-link">医生</span> </router-link> <router-link tag="div" class="tab-item" to="/family"> <div class="tab-icon family"></div> <span class="tab-link">家庭成员</span> </router-link> <router-link tag="div" class="tab-item" to="/my"> <div class="tab-icon my"></div> <span class="tab-link">我的</span> </router-link> </div></template>
<script type="text/ecmascript-6"> export default { create:function(){ }, data:function(){ return{ select:'home' } }, methods:{ } }</script>
<style> .nav{ position: fixed; height: 44px; left: 0; bottom: 0; width: 100%; border-top: 1px solid lightgray; display: flex; } .nav .tab-item{ flex: 1; text-align: center; align-items: center;// 垂直对齐方式(子元素在交叉轴的对齐方式) display: flex; flex-direction: column; } .tab-icon{ margin-top: 4px; display: inline-block; width: 14px; height: 18px; background-size: 14px 18px; } /*首页*/ .home{ background-image: url("../../assets/tabbar/tab_icon01_n@2x.png"); } .router-link-active .home{ background-image: url("../../assets/tabbar/tab_icon01_s@2x.png") } /*医生*/ .doctor{ background-image: url("../../assets/tabbar/tab_icon02_n@2x.png"); } .router-link-active .doctor{ background-image: url("../../assets/tabbar/tab_icon02_s@2x.png") } /*家庭成员*/ .family{ background-image: url("../../assets/tabbar/tab_icon04_n@2x.png"); } .router-link-active .family{ background-image: url("../../assets/tabbar/tab_icon04_s@2x.png") } /*我的*/ .my{ background-image: url("../../assets/tabbar/tab_icon05_n@2x.png"); } .router-link-active .my{ background-image: url("../../assets/tabbar/tab_icon05_s@2x.png") } .tab-link{ margin-top: 2px; color: gray; font-size: 12px; } .router-link-active .tab-link{ /*border-bottom 2px solid #50d2c2*/ color: #85d1ff; }
4.home
首页轮播图组件 vue-awesome-swiper
安装: npm install vue-awesome-swiper –save
在main.js中引入插件并使用
import VueAwesomeSwiper from 'vue-awesome-swiper'Vue.use(VueAwesomeSwiper)
由于可能不止一个页面会用到轮播图,可以把轮播图提取出
新建一个 slider.vue文件.
注意: 使用样式引入slider.css
<template> <div class="swiper-box" rel="swiperBox"> <swiper :options="swiperOption" class="swiper-container" ref="mySwiper"> <!-- 轮播项 --> <swiper-slide v-for="banner in banners"> <img :src="banner" class="swiper-image"> </swiper-slide> <!-- 轮播的小圆点 --> <div class="swiper-pagination" slot="pagination"> </div> </swiper> </div></template>
<script> import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { data:function() { return { } }, props:{ banners:{ type:Array }, swiperOption:{ } }, components:{ swiper:swiper, swiperSlide:swiperSlide }, //定义这个sweiper对象 computed: { swiper:function() { return this.$refs.mySwiper.swiper; } }, }</script>
<style> @import "swiper.css"; .swiper-box{ width: 100%; height: 180px; margin: 0 auto; } .swiper-box .swiper-container{ width: 100%; height: 100%; } .swiper-box .swiper-box img{ width: 100%; height: 100%; }</style>
在父组件里面import组件并传递参数
<template> <div class="home2"> <k-slider :banners="banners" :swiperOption="swiperOption"></k-slider> </div></template>
<script> import Slider from '../Common/Swiper/swiper.vue' export default { data:function(){ return{ banners:[ 'http://img.blog.csdn.net/20171016160652522?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHZsZW1v/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center', 'http://img.blog.csdn.net/20171016160701668?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHZsZW1v/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center' ], swiperOption:{ direction:'horizontal', loop:true, autoplay:1000, paginationType:'fraction', pagination:'.swiper-pagination' } } }, components:{ kSlider :Slider } }</script>
阅读全文
0 0
- vue导航和首页轮播图实现
- jQuery实现博客园首页导航
- Android ViewPager+TabHost实现首页导航
- 移动电子商务网站可用性-首页和导航
- vue-router配合ElementUI实现导航
- vue项目nav导航栏的实现
- vue和element框架搭配实现导航条跳转,点击按钮跳转页面导航条也跟着变换
- 怎么实现首页隐藏的 UINavigationBar 导航条
- 实现博客园首页导航菜单效果 前台代码
- 首页tab导航栏的实现原理及方法
- 从零开始搭建app—首页导航栏实现(一)
- vue + vue-touch 来实现移动端左右导航效果(有点像京东移动站导航)
- 模仿Google首页导航条的布局和样式
- pptv首页导航效果
- 仿微博首页顶部导航
- 实现左侧导航和横向导航
- Ecshop修改首页导航栏--“首页”
- 用Vue.js 和 vue-router 创建单页导航和分页
- 数据源-JNDI
- android apk 升级代码
- 线程独享
- spring mvc rest风格的URL输入中文乱码问题
- Spring+SpringMVC+MyBatis整合出现的Failed to load ApplicationContext的错误
- vue导航和首页轮播图实现
- 语句10.17
- 自定义注解,及应用
- springmvc mybatis,注解事务的使用
- sql 总结
- assign,copy,strong等关键字用法
- codes
- 高性能IO模型浅析
- [ubutnu桌面]ubutnu好看的桌面设计