0.1.2 • Published 5 years ago

vue-cus-tabs v0.1.2

Weekly downloads
14
License
-
Repository
github
Last release
5 years ago

Introduction

Vue-Cus-Tabs implements most of the common tab requirements, and you only need a simple configuration to render a tab on the page. Vue-Cus-Tabs has no dependencies other than Vue.

Vue-Cus-Tabs实现了大部分常见的tab需求,你只需要简单配置即可在页面上呈现一个tab。Vue-Cus-Tabs除了Vue以外没有任何依赖项。

demo:https://vue-cus-tabs-axel10.now.sh

Example

install:

npm i vue-cus-tabs -S

template:

    <CusTabWrap>
      <template v-slot:tabBar>
        <CusTabBar :style="{'height':'50px'}">
          <CusTabItem v-for="item in tabItems" :key="item.title">
            {{item.title}}
          </CusTabItem>
        </CusTabBar>
      </template>

      <template v-slot:tabContainer>
        <CusTabContainer>
          <CusTabContainerItem v-for="item in tabItems">
            <ul>
              <li v-for="data in item.data">
                {{data.title}}
              </li>
            </ul>
          </CusTabContainerItem>
        </CusTabContainer>
      </template>
    </CusTabWrap>

script:

  import Vue from 'vue'
  import 'vue-cus-tabs/style/index.css'
  import { installCusTabs } from 'vue-cus-tabs';
  Vue.use(installCusTabs);
  
  import { TabController } from 'vue-cus-tabs';
  import 'vue-cus-tabs/style/index.css'
 
  Vue.use(CusTabs);

  export default class Test extends Vue{
        public tabItems = [
          { title: '新闻', type: 'list', data: [{ img: '', title: 'list item title' }] },
          { title: '视频', type: 'block', data: [{ video: '', title: 'list item title' }] },
          { title: '视频1', type: 'block', data: [{ video: '', title: 'list item title' }] },
        ];
    public tabController?: TabController;
    public mounted() {
      this.tabController = new TabController({ data: this.tabItems, tabScroll: true, initIndex: 1 });
    }
  }

Configuration

Constructor:

nametypedetailrequireddefault value
dataarray用于渲染的数据true
selectorstring用于选择CusTabWrap组件false#__cus-tabs
activeColorstring指定已激活tab的文字颜色false
inactiveColorstring指定未激活tab的文字颜色false
initIndexnumber用于指定初始索引false0
reboundboolean指定tab处于左右边缘时滑动是否回弹falsefalse
tabScrollboolean指定tab是否可滚动falsefalse
durationnumber点击tabfalse#__cus-tabs
selectorstring用于选择CusTabWrap组件false#__cus-tabs
scrollEndOffsetnumber触发onScrollEnd事件的偏移false0
indicatorOptionsobject用于配置指示器的对象false
onScrollEnd(index: number) => void容器内容滚动到底部时的回调false
onChange(index: number, data: any) => void指定tab切换后的回调false

indicatorOptions:

nametypedetailrequireddefault value
backgroundColorstring指定指示器的颜色false#409eff
heightstring指定指示器的颜色falsetype
widthstring指定指示器的宽度,值可为'cover','content'或者百分比。如90%。为cover时宽度为整个tab项的宽度,为content时宽度为tab项内部内容的宽度。为百分比时宽度为内部内容宽度的百分比false2px

instance method:
实例方法:

nameparamsdetail
pushtabItem:object添加tab。参数为结构与data数组内元素相同的数据对象
removei:number移除指定序号的tab
changeTabtargetIndex: number, isAnimate?: boolean, time?: number切换到指定序号的tab。可以选择是否有动画以及动画时间。