Modal 模态框
vue
<template>
<ta-group title="基础用法">
<ta-cell label="默认" isLink @click="visible = true"></ta-cell>
<ta-cell
label="蒙层可点击"
isLink
@click="
() => {
maskClosable = true
visible = true
}
"
></ta-cell>
<ta-cell
label="隐藏关闭按钮"
isLink
@click="
() => {
maskClosable = true
showClose = false
visible = true
}
"
></ta-cell>
</ta-group>
<ta-group title="Slot default">
<ta-cell label="图片" isLink @click="visible2 = true"></ta-cell>
</ta-group>
<ta-group title="事件监听">
<ta-cell
label="cancel"
isLink
@click="
() => {
callbackEvent = true
maskClosable = true
visible = true
}
"
></ta-cell>
<ta-cell
label="visible-state-change"
isLink
@click="
() => {
visibleEvent = true
visible = true
}
"
></ta-cell>
</ta-group>
<ta-modal
v-model:visible="visible"
:maskClosable="maskClosable"
:showClose="showClose"
@cancel="onClose"
@visibleStateChange="onVisibleStateChange"
>
</ta-modal>
<ta-modal v-model:visible="visible2">
<ta-image class="exp-image-image" :src="imageUrl" :aspectRatio="1"></ta-image>
</ta-modal>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { type PopupOnCancel, type PopupOnVisibleStateChange, showToast } from '@/index'
export default defineComponent({
name: 'ExpModal',
setup() {
const visible = ref(false)
const maskClosable = ref(false)
const showClose = ref(true)
const callbackEvent = ref(false)
const visibleEvent = ref(false)
const visible2 = ref(false)
const onVisibleStateChange: PopupOnVisibleStateChange = ({ state }) => {
if (visibleEvent.value) {
console.log('visible-state-change', state)
showToast(`${state} 事件触发`)
}
if (state === 'hidden') {
callbackEvent.value = false
visibleEvent.value = false
maskClosable.value = false
showClose.value = true
}
}
const onClose: PopupOnCancel = res => {
console.log('cancel', res)
if (callbackEvent.value) {
if (res.source === 'closeClick') {
showToast('点击了关闭按钮')
} else if (res.source === 'maskClick') {
showToast('点击了蒙层')
}
}
}
return {
visible,
maskClosable,
showClose,
callbackEvent,
visibleEvent,
visible2,
imageUrl: 'https://cdn.fox2.cn/vfox/swiper/center-2.jpg',
onVisibleStateChange,
onClose
}
}
})
</script>
Import
js
import { TaModal } from 'tantalum-ui-mobile'
具体的引入方式可以参考引入组件。
Import Type
组件导出的类型定义:
ts
import type { VisibleState, PopupOnVisibleStateChange, PopupOnCancel } from 'tantalum-ui-mobile'
Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
v-model:visible | boolean | false | 否 | 是否显示 |
width | string | 否 | 模态框的宽度,支持 CSS 宽度值 | |
mask-closable | boolean | false | 否 | 点击蒙层是否触发关闭操作 |
show-close | boolean | true | 否 | 是否显示关闭按钮 |
Events
事件 | 描述 | 回调函数参数 | TypeScript 函数 |
---|---|---|---|
visible-state-change | 展示隐藏时触发 | payload: { state: VisibleState } | PopupOnVisibleStateChange |
cancel | 关闭按钮或者点击蒙层关闭时触发 | payload: { source: string } | PopupOnCancel |
VisibleState 值说明
值 | 说明 | 备注 |
---|---|---|
show | 展示时触发 | |
shown | 展示且动画结束后触发 | |
hide | 隐藏时触发 | 可能携带其他参数 cancel, maskClick, closeClick 等 |
hidden | 隐藏且动画结束后触发 | 可能携带其他参数 cancel, maskClick, closeClick 等 |