Popover
组件类型:UxPopoverComponentPublicInstance
支持任何位置弹出并且自动计算在适当的位置显示
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
targetId | String | 目标id | |
width | Any | 宽度 | |
offset | Any | 10 | 偏移 |
align | Boolean | false | 与目标水平对齐 |
backgroundColor | String | #000000 | 背景色 |
showMask | Boolean | true | 显示遮罩 |
showBlur | Boolean | false | 开启模糊背景 |
blurRadius | Number | 10 | 模糊半径 |
blurColor | String | rgba(10,10,10,0.3) | 模糊颜色 |
opacity | Number | $ux.Conf.maskAlpha | 遮罩透明度0-1 |
zIndex | Number | 10001 | 层级z-index |
Events
事件名 | 说明 | 参数 |
---|---|---|
change | 显示状态改变时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<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-scroll>
<ux-card direction="column" icon="flag-filled" title="弹出层" :bold="true">
<ux-text text="支持任何位置弹出并且自动计算在适当的位置显示"></ux-text>
</ux-card>
</ux-scroll>
<view id="lt" class="lt">
<ux-button theme="primary" text="左上" @click="click('lt', false)"></ux-button>
</view>
<view id="ct" class="ct">
<ux-button theme="primary" text="中上 - 水平对齐" @click="click('ct', true)"></ux-button>
</view>
<view id="rt" class="rt">
<ux-button theme="primary" text="右上" @click="click('rt', false)"></ux-button>
</view>
<view id="lc" class="lc">
<ux-button theme="primary" text="左中" @click="click('lc', false)"></ux-button>
</view>
<view id="c" class="c">
<ux-button theme="primary" text="中" @click="click('c', false)"></ux-button>
</view>
<view id="rc" class="rc">
<ux-button theme="primary" text="右中" @click="click('rc', false)"></ux-button>
</view>
<view id="lb" class="lb">
<ux-button theme="primary" text="左下" @click="click('lb', false)"></ux-button>
</view>
<view id="cb" class="cb">
<ux-button theme="primary" text="中下 - 水平对齐" @click="click('cb', true)"></ux-button>
</view>
<view id="rb" class="rb">
<ux-button theme="primary" text="右下" @click="click('rb', false)"></ux-button>
</view>
<ux-popover ref="uxPopoverRef" :targetId="targetId" :align="align">
<ux-cell :title="it.name" :icon="it.icon" :border="i < btns.length - 1" :rightArrow="false"
color="white" iconColor="white" :hover="false" v-for="(it, i) in btns" :key="i"></ux-cell>
</ux-popover>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<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-scroll>
<ux-card direction="column" icon="flag-filled" title="弹出层" :bold="true">
<ux-text text="支持任何位置弹出并且自动计算在适当的位置显示"></ux-text>
</ux-card>
</ux-scroll>
<view id="lt" class="lt">
<ux-button theme="primary" text="左上" @click="click('lt', false)"></ux-button>
</view>
<view id="ct" class="ct">
<ux-button theme="primary" text="中上 - 水平对齐" @click="click('ct', true)"></ux-button>
</view>
<view id="rt" class="rt">
<ux-button theme="primary" text="右上" @click="click('rt', false)"></ux-button>
</view>
<view id="lc" class="lc">
<ux-button theme="primary" text="左中" @click="click('lc', false)"></ux-button>
</view>
<view id="c" class="c">
<ux-button theme="primary" text="中" @click="click('c', false)"></ux-button>
</view>
<view id="rc" class="rc">
<ux-button theme="primary" text="右中" @click="click('rc', false)"></ux-button>
</view>
<view id="lb" class="lb">
<ux-button theme="primary" text="左下" @click="click('lb', false)"></ux-button>
</view>
<view id="cb" class="cb">
<ux-button theme="primary" text="中下 - 水平对齐" @click="click('cb', true)"></ux-button>
</view>
<view id="rb" class="rb">
<ux-button theme="primary" text="右下" @click="click('rb', false)"></ux-button>
</view>
<ux-popover ref="uxPopoverRef" :targetId="targetId" :align="align">
<ux-cell :title="it.name" :icon="it.icon" :border="i < btns.length - 1" :rightArrow="false"
color="white" iconColor="white" :hover="false" v-for="(it, i) in btns" :key="i"></ux-cell>
</ux-popover>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxBtn } from '@/uni_modules/ux-frame'
const title = ref('')
const targetId = ref('lt')
const align = ref(false)
const uxPopoverRef = ref<UxPopoverComponentPublicInstance | null>(null)
const btns = [{
name: '扫一扫',
icon: 'scan-outline',
}, {
name: '关于',
icon: 'help-outline',
}, {
name: '设置',
icon: 'setting-outline',
}] as UxBtn[]
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/popover.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function click(_id : string, _align : boolean) {
targetId.value = _id
align.value = _align
uxPopoverRef.value?.$callMethod('open')
}
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxBtn } from '@/uni_modules/ux-frame'
const title = ref('')
const targetId = ref('lt')
const align = ref(false)
const uxPopoverRef = ref<UxPopoverComponentPublicInstance | null>(null)
const btns = [{
name: '扫一扫',
icon: 'scan-outline',
}, {
name: '关于',
icon: 'help-outline',
}, {
name: '设置',
icon: 'setting-outline',
}] as UxBtn[]
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/popover.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function click(_id : string, _align : boolean) {
targetId.value = _id
align.value = _align
uxPopoverRef.value?.$callMethod('open')
}
</script>
css
<style lang="scss">
.lt {
position: fixed;
top: 205px;
left: 15px;
}
.ct {
position: fixed;
top: 205px;
left: 45%;
}
.rt {
position: fixed;
top: 205px;
right: 15px;
}
.lc {
position: fixed;
top: 50%;
left: 15px;
}
.c {
position: fixed;
top: 50%;
left: 48%;
}
.rc {
position: fixed;
top: 50%;
right: 15px;
}
.lb {
position: fixed;
bottom: 30px;
left: 15px;
}
.cb {
position: fixed;
bottom: 30px;
left: 45%;
}
.rb {
position: fixed;
bottom: 30px;
right: 15px;
}
</style>
<style lang="scss">
.lt {
position: fixed;
top: 205px;
left: 15px;
}
.ct {
position: fixed;
top: 205px;
left: 45%;
}
.rt {
position: fixed;
top: 205px;
right: 15px;
}
.lc {
position: fixed;
top: 50%;
left: 15px;
}
.c {
position: fixed;
top: 50%;
left: 48%;
}
.rc {
position: fixed;
top: 50%;
right: 15px;
}
.lb {
position: fixed;
bottom: 30px;
left: 15px;
}
.cb {
position: fixed;
bottom: 30px;
left: 45%;
}
.rb {
position: fixed;
bottom: 30px;
right: 15px;
}
</style>