Sidebar
组件类型:UxSidebarComponentPublicInstance
支持滑动距离自动切换到锚点
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
default | Slot | 默认插槽 | |
theme | String | info | 按钮类型 |
modelValue | Number | 0 | 双向绑定值 |
datas | UxTab[] | sidebar列表 | |
type | String | line | 类型 |
anim | String | scroll | 动效类型 |
anchorId | String | 锚点ScrollId | |
width | Any | auto | 宽度 |
height | Any | auto | 高度 |
tabWidth | Any | 100 | Tab宽度 |
tabHeight | Any | 44 | Tab高度 |
corner | Any | 0 | 圆角 |
selectedColor | String | $ux.Conf.fontColor | 选中颜色 |
unselectedColor | String | $ux.Conf.fontColor | 未选中颜色 |
background | String | $ux.Conf.backgroundColor | 背景色 |
backgroundDark | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
lineColor | String | 线颜色selectedColor优先级更高 | |
lineWidth | Any | 2 | 线宽度0则自动适配 |
lineHeight | Any | 30 | 线高度、点直径 |
fontSize | Any | $ux.Conf.fontSize | 字体大小 |
selectSize | Any | $ux.Conf.fontSize | 选中字体大小 |
bold | Boolean | false | 字体加粗 |
selectBold | Boolean | false | 选中字体加粗 |
duration | Number | 300 | 过渡时间 |
padding | Any | 12 | 内部padding |
offset | Any | 0 | 锚点偏移距离 |
theme
值 | 说明 |
---|---|
text | 文字 |
info | 默认 |
primary | 主要 |
success | 成功 |
warning | 警告 |
error | 错误 |
type
值 | 说明 |
---|---|
none无 | |
line下划线 | |
point点 |
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-sidebar ref="uxSidebarRef"
:height="250"
anchorId="tabscroll"
type="line"
theme="success"
:font-size="13"
:select-size="13"
:line-height="0"
:corner="5"
v-model="tabIndex"
:datas="tabs">
<scroll-view style="height: 250px;" id="tabscroll" direction="vertical" :scroll-with-animation="true" :show-scrollbar="false" @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-sidebar>
</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-sidebar ref="uxSidebarRef"
:height="250"
anchorId="tabscroll"
type="line"
theme="success"
:font-size="13"
:select-size="13"
:line-height="0"
:corner="5"
v-model="tabIndex"
:datas="tabs">
<scroll-view style="height: 250px;" id="tabscroll" direction="vertical" :scroll-with-animation="true" :show-scrollbar="false" @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-sidebar>
</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 uxSidebarRef = ref<UxSidebarComponentPublicInstance | null>(null)
const isPress = ref(false)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/sidebar.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
function presss() {
isPress.value = true
}
function scroll(e: ScrollEvent) {
if(isPress.value) {
uxSidebarRef.value?.$callMethod('toAnchor', e)
}
$ux.Util.debounce(() => {
isPress.value = false
}, 1000)
}
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 uxSidebarRef = ref<UxSidebarComponentPublicInstance | null>(null)
const isPress = ref(false)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/sidebar.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
function presss() {
isPress.value = true
}
function scroll(e: ScrollEvent) {
if(isPress.value) {
uxSidebarRef.value?.$callMethod('toAnchor', e)
}
$ux.Util.debounce(() => {
isPress.value = false
}, 1000)
}
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>