Vue2+VueRouter2+webpack 构建项目实战(六)加入tab栏切换,拓展项目

本文参考 fungLeo大神的博客,本人现在学习vue,仅仅当做笔记。大神链接:http://blog.csdn.net/fungleo/article/details/53171052奋斗

好了,开始开动吧!!!

首先安装以下目录创建文件夹


然后相应的文件里面加入代码

//happy.vue
<template>
  <div class="title">user happy page</div>
</template>

//index.vue
<template>
  <div class="title">这个就是更加详细的页面~~~</div>
</template>
<script>
	export default {
		data () {
			return {

			}
		}
	}
</script>

//info.vue
<template>
  <div class="title">
        <router-link to="/user/">
           点击详情更加详细~~~
        </router-link>
   </div>
</template>

//like.vue
<template>
  <div class="title">user like page</div>
</template>

//love.vue
<template>
  <div class="title">user love page</div>
</template>


然后 routes.js文件添加代码

import index from '../page/index.vue'
import content from '../page/content.vue'
// 配置路由
import Frame from '../frame/subroute.vue'
// 引入子页面
import userIndex from '../page/user/index.vue'
import userInfo from '../page/user/info.vue'
import userLove from '../page/user/love.vue'
import userLike from '../page/user/like.vue'
import userHappy from '../page/user/happy.vue'

export default [
  {
    path: '/',
    component: index
  },
  {
    path: '/content',
    component: content
  },
  {
	  path: '/user',
	  component: Frame,
	  children: [
	    {path: '/',component: userIndex},
	    {path: 'info',component: userInfo},
      {path: 'love',component: userLove},
      {path: 'like',component: userLike},
	    {path: 'happy',component: userHappy}
	  ],
	},
]

_common.scss文件  总得加点样式吧

	.title{
		font-size: 40px;
		margin-top: 50px;
		color: #e4393c;
	}

当然 style.scss必须引入

$static:"/static";
// base
@import "base/color";
@import "base/base";
@import "base/mixin";
@import "base/reset";
@import "base/font";
// style
@import "scss/index";
@import "scss/common";
最后一部分 App.vue 然后就可以看到效果了

<style>
  .router-link-active {
    color: #E4393C;
    font-size:22px;
  }
  .fade-enter-active,.fade-leave-acitve {
    transition: opacity .4s;
  }
  .fade-enter,.fade-leave-acitve {
    opacity: 0;
  }
  .main,.slide-nav{
    height: 60px;
  }
  .slide-out li{
    float: left;
    height: 60px;
    width: 120px;
    background-color: #ddd;
    font-size: 22px;
    line-height: 60px;
    margin-left: 2px;
    text-align: center;
  }
  .img{
    width: 100%;
  }
  img{
    width: 100%;
  }
</style>
<template>
  <div  class="main">
    <div class="img"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2139964329,1339306013&fm=15&gp=0.jpg" alt=""></div>
    <div class="slide-nav">
      <ul class="slide-out">
        <li class="index_1"><router-link  to="/" exact>文章专区</router-link></li>
        <li class="info_1"><router-link  to="/user/info">图片专区</router-link></li>
        <li class="love_1"><router-link  to="/user/love">音乐专区</router-link></li>
        <li class="like_1"><router-link  to="/user/like">电影专区</router-link></li>
        <li class="happy_1"><router-link  to="/user/happy">用户留言</router-link></li>
      </ul>
    </div>
    <div class="content">
          <transition name="fade"><router-view class="view" keep-alive transition-mode="out-in" :key="key"></router-view></transition>
    </div>
  </div>
</template>
<script>
  export default {
    components: {},
    computed: {
          key() {
              return this.$route.path.replace(/\//g, '_')
          }
    }
  }
</script>

<style lang="scss">
  @import "./style/style.scss";
</style>

duang~duang~duang~效果出来了  tab栏复用点击切换页面内容,点击内容进入下一级奋斗

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值