Skip to content
本页导读

Anchor Tabs

组件类型:UxTabsComponentPublicInstance

支持点、下划线、微笑类型,下划线支持左右滚动、左右推压效果

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
leftSlot左插槽
rightSlot右插槽
themeStringinfo按钮类型
modelValueNumber0双向绑定值
datasUxTab[]tabs列表
typeStringline类型
animStringscroll动效类型
anchorIdString锚点ScrollId
anchorBooleanfalse自动滚动到锚点
widthAnyauto宽度
heightAny44高度
cornerAny0圆角
selectedColorString$ux.Conf.fontColor选中颜色
unselectedColorString$ux.Conf.fontColor未选中颜色
backgroundString$ux.Conf.backgroundColor背景色
backgroundDarkString深色none-不显示,auto-自动适配深色模式,其他-颜色
lineColorString线颜色selectedColor优先级更高
lineWidthAny20线宽度0则自动适配
lineHeightAny2线高度、点直径
fontSizeAny$ux.Conf.fontSize字体大小
selectSizeAny$ux.Conf.fontSize选中字体大小
boldBooleanfalse字体加粗
selectBoldBooleanfalse选中字体加粗
paddingAny12内部padding
durationNumber300过渡时间
offsetAny0锚点偏移距离

theme

说明
text文字
info默认
primary主要
success成功
warning警告
error错误

type

说明
none无
line下划线
point点
smile微笑

anim

说明
none无
scroll左右滚动
push左右推压

backgroundDark

说明
none不显示
auto自动适配深色模式
color其他颜色

Events

事件名说明参数
change当前选择下标改变时触发
anchor当要滚动目标时触发

示例代码

html
<template>
  <ux-page :stack="showDoc">
    <ux-navbar :title="title" :border="false">
      <template v-slot:right>
        <!-- #ifndef MP -->
        <ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
        <!-- #endif -->
      </template>
    </ux-navbar>

    <ux-card direction="column" icon="flag-filled" title="锚点选项卡" :bold="true">
      <ux-text text="支持滑动距离自动切换到锚点"></ux-text>
    </ux-card>

    <ux-card direction="column" icon="arrowright" title="自动滚动到锚点" :bold="true">
      <ux-tabs ref="uxTabsRef" :anchor="true" anchorId="tabscroll" theme="success" :line-width="0" v-model="tabIndex" :datas="tabs" @anchor="onAnchor"></ux-tabs>

      <scroll-view id="tabscroll" style="height: 400px;" :scroll-y="true" :scroll-top="scrollTop" :show-scrollbar="false" :scroll-with-animation="true" @touchstart="presss" @mousedown="presss" @scroll="scroll">
        <view id="tab1" class="b">
          <text class="text">{{ tabs[0].name }}</text>
        </view>
        <view id="tab2" class="b2">
          <text class="text">{{ tabs[1].name }}</text>
        </view>
        <view id="tab3" class="b">
          <text class="text">{{ tabs[2].name }}</text>
        </view>
        <view id="tab4" class="b2">
          <text class="text">{{ tabs[3].name }}</text>
        </view>
        <view id="tab5" class="b">
          <text class="text">{{ tabs[4].name }}</text>
        </view>
        <view id="tab6" class="b2">
          <text class="text">{{ tabs[5].name }}</text>
        </view>
        <view id="tab7" class="b">
          <text class="text">{{ tabs[6].name }}</text>
        </view>
      </scroll-view>
    </ux-card>

    <ux-placeholder :height="200">
      <ux-row justify="center" align="center" style="height: 100%;">
        <ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
      </ux-row>
    </ux-placeholder>
  </ux-page>
</template>
<template>
  <ux-page :stack="showDoc">
    <ux-navbar :title="title" :border="false">
      <template v-slot:right>
        <!-- #ifndef MP -->
        <ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
        <!-- #endif -->
      </template>
    </ux-navbar>

    <ux-card direction="column" icon="flag-filled" title="锚点选项卡" :bold="true">
      <ux-text text="支持滑动距离自动切换到锚点"></ux-text>
    </ux-card>

    <ux-card direction="column" icon="arrowright" title="自动滚动到锚点" :bold="true">
      <ux-tabs ref="uxTabsRef" :anchor="true" anchorId="tabscroll" theme="success" :line-width="0" v-model="tabIndex" :datas="tabs" @anchor="onAnchor"></ux-tabs>

      <scroll-view id="tabscroll" style="height: 400px;" :scroll-y="true" :scroll-top="scrollTop" :show-scrollbar="false" :scroll-with-animation="true" @touchstart="presss" @mousedown="presss" @scroll="scroll">
        <view id="tab1" class="b">
          <text class="text">{{ tabs[0].name }}</text>
        </view>
        <view id="tab2" class="b2">
          <text class="text">{{ tabs[1].name }}</text>
        </view>
        <view id="tab3" class="b">
          <text class="text">{{ tabs[2].name }}</text>
        </view>
        <view id="tab4" class="b2">
          <text class="text">{{ tabs[3].name }}</text>
        </view>
        <view id="tab5" class="b">
          <text class="text">{{ tabs[4].name }}</text>
        </view>
        <view id="tab6" class="b2">
          <text class="text">{{ tabs[5].name }}</text>
        </view>
        <view id="tab7" class="b">
          <text class="text">{{ tabs[6].name }}</text>
        </view>
      </scroll-view>
    </ux-card>

    <ux-placeholder :height="200">
      <ux-row justify="center" align="center" style="height: 100%;">
        <ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
      </ux-row>
    </ux-placeholder>
  </ux-page>
</template>
ts
<script setup>

import * as plus from '@/uni_modules/ux-plus'
import { $ux, UxTab } from '@/uni_modules/ux-frame'

const title = ref('')

const tabs = [
  {
    anchorId: 'tab1',
    name: '基础组件',
  },
  {
    anchorId: 'tab2',
    name: '表单组件',
    badge: 10
  },
  {
    anchorId: 'tab3',
    name: '反馈组件',
  },
  {
    anchorId: 'tab4',
    name: '展示组件',
  },
  {
    anchorId: 'tab5',
    name: '导航组件',
    badge: 100,
  },
  {
    anchorId: 'tab6',
    name: '布局组件',
  },
  {
    anchorId: 'tab7',
    name: '其他组件',
  }
] as UxTab[]

const tabIndex = ref(0)
const scrollTop = ref(0)
const uxTabsRef = ref<UxTabsComponentPublicInstance | null>(null)

const isPress = ref(false)

function presss() {
  isPress.value = true
}

function scroll(e: ScrollEvent) {
  if(isPress.value) {
    uxTabsRef.value?.$callMethod('toAnchor', e)
  }

  $ux.Util.debounce(() => {
    isPress.value = false
  }, 1000)
}

const showDoc = ref(false)

function onDoc() {
  plus.openWeb({
    title: '在线文档',
    url: 'https://www.uxframe.cn/component/anchortabs.html',
    // blur: 1,
    success: () => {
      showDoc.value = true
    },
    complete: () => {
      showDoc.value = false
    }
  })
}

function onAnchor(val: number) {
  scrollTop.value = val
}

onLoad((e) => {
  title.value = e['title'] ?? ''
})
</script>
<script setup>

import * as plus from '@/uni_modules/ux-plus'
import { $ux, UxTab } from '@/uni_modules/ux-frame'

const title = ref('')

const tabs = [
  {
    anchorId: 'tab1',
    name: '基础组件',
  },
  {
    anchorId: 'tab2',
    name: '表单组件',
    badge: 10
  },
  {
    anchorId: 'tab3',
    name: '反馈组件',
  },
  {
    anchorId: 'tab4',
    name: '展示组件',
  },
  {
    anchorId: 'tab5',
    name: '导航组件',
    badge: 100,
  },
  {
    anchorId: 'tab6',
    name: '布局组件',
  },
  {
    anchorId: 'tab7',
    name: '其他组件',
  }
] as UxTab[]

const tabIndex = ref(0)
const scrollTop = ref(0)
const uxTabsRef = ref<UxTabsComponentPublicInstance | null>(null)

const isPress = ref(false)

function presss() {
  isPress.value = true
}

function scroll(e: ScrollEvent) {
  if(isPress.value) {
    uxTabsRef.value?.$callMethod('toAnchor', e)
  }

  $ux.Util.debounce(() => {
    isPress.value = false
  }, 1000)
}

const showDoc = ref(false)

function onDoc() {
  plus.openWeb({
    title: '在线文档',
    url: 'https://www.uxframe.cn/component/anchortabs.html',
    // blur: 1,
    success: () => {
      showDoc.value = true
    },
    complete: () => {
      showDoc.value = false
    }
  })
}

function onAnchor(val: number) {
  scrollTop.value = val
}

onLoad((e) => {
  title.value = e['title'] ?? ''
})
</script>
css
<style lang="scss">
    .b {
           width: 100%;
           height: 200px;
           background-color: sandybrown;
           display: flex;
           flex-direction: column;
           align-items: center;
           justify-content: center;

          .text {
              font-size: 16px;
              color: black;
          } 
   }

    .b2 {
        @extend .b;
        background-color: skyblue;
    }
</style>
<style lang="scss">
    .b {
           width: 100%;
           height: 200px;
           background-color: sandybrown;
           display: flex;
           flex-direction: column;
           align-items: center;
           justify-content: center;

          .text {
              font-size: 16px;
              color: black;
          } 
   }

    .b2 {
        @extend .b;
        background-color: skyblue;
    }
</style>