Skip to content

XTabs 选项卡

示例

基础用法

<template>
  <div class="page">
    <XTabs
      :items="items"
      v-model="currentValue"
      border
      @action-click="onClick"
      @action-command="onCommand"></XTabs>

    <XTabs
      :items="items"
      v-model="currentValue"
      align="right"
      @action-click="onClick"
      @action-command="onCommand"></XTabs>

    <XTabs
      :items="items"
      type="card"
      closable
      stretch
      v-model="currentValue"
      @action-click="onClick"
      @actionCommand="onCommand"></XTabs>
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { XTabs, type TabsItem } from '@vtj/ui';
  import { Setting, DeleteFilled } from '@vtj/icons';

  const currentValue = ref(1);

  const items: TabsItem[] = [
    {
      label: '选项面板一',
      name: 1,
      lazy: true,
      data: [1]
    },
    {
      label: '选项面板二',
      name: 2,
      lazy: true,
      data: [2]
    },
    {
      label: '选项面板三',
      name: 3,
      lazy: true,
      data: [3],
      actions: [
        {
          name: 'add',
          icon: Setting
        },
        {
          name: 'remove',
          icon: DeleteFilled
        }
      ]
    }
  ];

  const onClick = (e: any) => {
    console.log('click-icon', e);
  };

  const onCommand = (e: any) => {
    console.log('click-command', e);
  };
</script>

<style scoped>
  .page {
    display: flex;
    flex-direction: column;
    gap: 30px;
  }
</style>

插槽用法

<template>
  <div class="page">
    <XTabs :items="items" v-model="currentValue">
      <template #default="{ name }">
        <MyComp :name="name"></MyComp>
        <!-- <div>{{ Date.now() }} {{ console.log('tab', name) }}</div> -->
      </template>
    </XTabs>
  </div>
</template>

<script setup lang="ts">
  import { ref, defineComponent, h } from 'vue';
  import { XTabs, type TabsItem } from '@vtj/ui';
  import { Setting, DeleteFilled } from '@vtj/icons';

  const currentValue = ref(1);

  const MyComp = defineComponent({
    props: {
      name: [String, Number, Array]
    },
    render() {
      console.log('render', this.name);
      return h('div', 'hello:' + this.name);
    },
    mounted() {
      console.log('mounted');
    },
    updated() {
      console.log('updated');
    }
  });

  const items: TabsItem[] = [
    {
      label: '选项面板一',
      name: 1,
      lazy: true,
      data: [1]
    },
    {
      label: '选项面板二',
      name: 2,
      lazy: true,
      data: [2]
    },
    {
      label: '选项面板三',
      name: 3,
      lazy: true,
      data: [3],
      actions: [
        {
          name: 'add',
          icon: Setting
        },
        {
          name: 'remove',
          icon: DeleteFilled
        }
      ]
    }
  ];
</script>

<style scoped>
  .page {
    display: flex;
    flex-direction: column;
    gap: 30px;
  }
</style>

API

属性

属性名说明类型默认值
items选项array[]
border显示下划线booleanfalse
fit自适应宽高boolean-
align对齐方式string< left | center | right >left
modelValue当前激活项number1
type选项卡类型string <card | border-card>-
closable展示删除的图标booleanfalse
addable展示添加的图标booleanfalse
editable展示编辑的图标booleanfalse
tabPosition选项卡位置stringtop
stretch伸展booleanfalse
beforeLeave

事件

名称说明类型
actionClick点击图标时触发-
actionCommand点击每一项时触发-

插槽

名称说明类型
default--

Released under the MIT License.