vue组件化思想应用之tabbar

10 篇文章 0 订阅
9 篇文章 0 订阅

vue组件化思想应用之tabbar

App.vue调用了TabBar.vue和TabbarItem.vue

其中App.vue

html代码

<template>
  <div id="app">
    <tab-bar>
      <tab-bar-item v-for="(value,name) in tabbar" :key="name">
        <img slot="item-icon" :src="require('./assets/img/tabbar/'+name+'.svg')" alt="">
        <div slot="item-text">{{value}}</div>
      </tab-bar-item>
    </tab-bar>
  </div>
</template>

javascript代码

<script>
  import TabBar from "./components/tabbar/TabBar";    //导入
  import TabBarItem from "./components/tabbar/TabBarItem";    //导入
  export default {
    name: 'App',          //这个组件名叫App
    data(){
      return {
        tabbar: {
          home: '首页',
          category: '分类',
          shopcart: '购物车',
          profile: '我的',
        }
      }
    },
    components: {
      TabBarItem,
      TabBar,
    },
  }
</script>

TabBar.vue

html

<template>
  <div id="tab-bar">
<!--    很简单的设置一个插槽-->
    <slot></slot>		
  </div>
</template>

javascript

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

css我们在这里就把对应的层次css写好

<style scoped>
  #tab-bar {
    display: flex;
    background-color: #f6f6f6;
    height: 49px;
    position: fixed;
    width: 100%;
    bottom: 0;
    /*justify-content: space-between;*/
    box-shadow: 0 -3px 1px rgba(100,100,100,0.2);
  }
</style>

TabBarItem.vue

html

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

JavaScript

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

css 同样的把对应层次的css写好

<style scoped>
.tab-bar-item {
  flex:1;
  text-align: center;
  font-size: 13px;
}
.tab-bar-item  img{
  width: 24px;
  height: 24px;
  margin-top: 4px;
  margin-bottom: 2px;
  vertical-align: middle;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值