vue学习记录 coderwhy d9

$this.router = router

$this,route是当前处于活跃的路由

在这里插入图片描述
观察者模式。一对多,一个是改了的data,多是更新数据
导航守卫
在这里插入图片描述

{
      path:'/About',
      component: About,
      beforeEnter:(to,from,next)=>{
        console.log('About beforeEnter')
      }

导航守卫配置:

beforeRouteEnter(to,from,next){
    // document.title = to.meta
    next(false)
  }
}
import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
// import Home from "../components/Home";
// import About from "../components/About";
// import User from "../components/User";
const Home=()=>import('../components/Home');
const About=()=>import('../components/About');
const User=()=>import('../components/User');
const HomeNews=()=>import('../components/HomeNews');
const HomeMessage=()=>import('../components/HomeMessage');

// const HelloWorld=()=>import('../components/HelloWorld');

Vue.use(Router)

const routes= [
    {
      path:'',
      redirect: '/Home'
    },
    {
      path: '/Home',
      component: Home,
      meta:"Home",
      children:[{
        path:'news',
        component:HomeNews,
        meta:"news",

      },{
        path:'message',
        component:HomeMessage,
        meta:"message",
      }]
    },
    {
      path:'/About',
      component: About,
      meta:"About",
      beforeEnter:(to,from,next)=>{
        console.log('About beforeEnter')
         next()
      }
    },{
      path: '/User/:userId',
      component: User
    }
  ]
  // mode:'history'

const router = new Router({
  routes,
  mode:'history'

})

router.beforeEach((to,from,next)=>{
  document.title = to.meta;
  next()
})

export default router;

官方文档

<keep-alive><router-view></router-view>
    </keep-alive>

在这里插入图片描述
在这里插入图片描述
tabbar
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<template>
  <div id="tab-bar">
    <div class="tab-bar-item">首页</div>
    <div class="tab-bar-item">分类</div>
    <div class="tab-bar-item">购物车</div>
    <div class="tab-bar-item">我的</div>
  </div>
</template>

<script>
export default {
  name: "TabBar"
}
</script>

<style scoped>
*{
  padding: 0;
  margin: 0;
}
#tab-bar{
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0px -1px 1px rgba(100,100,100,0.2);
}
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  background-color: #f6f6f6;
}

</style>

App.vue

<template>
  <div id="app">
    <tab-bar>
      <tab-bar-item>
        <img slot="item-icon" src="./assets/img/tabbar/indexactive.png" height="20" width="20">
        <div slot="item-text">主页</div>
      </tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/Category2.png" height="20" width="20">
        <div slot="item-text">分类</div>
      </tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/shop-cart-.png" height="20" width="20">
        <div slot="item-text">购物车</div></tab-bar-item>
      <tab-bar-item><img slot="item-icon" src="./assets/img/tabbar/Profile_1.png" height="20" width="20">
        <div slot="item-text">我的</div></tab-bar-item>
    </tab-bar>
  </div>

</template>

<script>
import TabBar from "./components/tabbar/TabBar";
import TabBarItem from "./components/tabbar/TabBarItem";
export default {
  name: 'App',
  components:{
    TabBar,
    TabBarItem
  }
}
</script>

<style >
</style>

tabbaritem.vue

<template>
  <div class="tab-bar-item">
    <slot name="item-icon"></slot>
    <slot name="item-text"></slot>
  </div>
</template>

<script>
export default {
  name: "TabBarItem"
}
</script>

<style scoped>
*{
  padding: 0;
  margin: 0;
}
.tab-bar{
  height: 49px;
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0px -1px 1px rgba(100,100,100,0.2);
}
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  background-color: #f6f6f6;
  font-size: 14px;
  margin-top: 3px;
  vertical-align: middle;
}

</style>

tabbar.vue

<template>
  <div id="tab-bar">
    <slot></slot> </div>
</template>

<script>
export default {
  name: "TabBar"
}
</script>

<style scoped>

#tab-bar{
  height: 49px;
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0px -1px 1px rgba(100,100,100,0.2);
}

</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值