Skip to content

VideoPreview ​

Video preview component, supports opening full-screen video preview layer through component instance or useVideoPreview function call. For standalone usage and API details of useVideoPreview, see useVideoPreview.

Note

Before using useVideoPreview(), you need to declare a wd-video-preview instance in the current page, otherwise the injection relationship cannot be established.

Component Types ​

useVideoPreview ​

useVideoPreview is the recommended way to call wd-video-preview, suitable for directly launching video preview in interactions like button clicks, list item clicks. For detailed instructions, see useVideoPreview.

Basic Usage ​

The usage corresponding to the current demo page is to place a wd-video-preview instance in the page, and then open the preview through previewVideo().

html
<wd-button @click="open">Click to preview video</wd-button>

<wd-video-preview />
ts
import { useVideoPreview } from '@/uni_modules/wot-ui/components/wd-video-preview'
import type { PreviewVideo } from '@/uni_modules/wot-ui/components/wd-video-preview/types'

const { previewVideo } = useVideoPreview()

const video: PreviewVideo = {
  url: 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4',
  poster: 'https://wot-ui.cn/assets/panda.jpg',
  title: 'Video Preview'
}

function open() {
  previewVideo(video)
}

Special Styles ​

Multi-instance Calls ​

When multiple wd-video-preview instances exist on the same page, you can distinguish them through selector, and pass the same identifier in useVideoPreview(selector).

html
<wd-button @click="openMain">Open Main Preview</wd-button>
<wd-button @click="openSub">Open Secondary Preview</wd-button>

<wd-video-preview />
<wd-video-preview selector="sub-preview" />
ts
import { useVideoPreview } from '@/uni_modules/wot-ui/components/wd-video-preview'

const { previewVideo: openMainPreview } = useVideoPreview()
const { previewVideo: openSubPreview } = useVideoPreview('sub-preview')

Custom Z-index and Callbacks ​

When calling functionally, you can directly pass zIndex, closePosition, onOpen, onClose, and the component will prioritize configurations passed functionally.

ts
previewVideo({
  url: 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4',
  poster: 'https://wot-ui.cn/assets/panda.jpg',
  title: 'Video Preview',
  zIndex: 1200,
  closePosition: 'right-top',
  onOpen: () => console.log('Open preview'),
  onClose: () => console.log('Close preview')
})

Fullscreen Preview ​

Use full-screen to make the video area fill the preview layer, which is suitable for portrait videos.

html
<wd-video-preview full-screen />

When using programmatic calls, you can also pass fullScreen to previewVideo.

ts
previewVideo({
  url: 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4',
  title: 'Fullscreen Video',
  fullScreen: true
})

Component Instance Calls ​

If you prefer component-style control, you can also call instance methods open and close through ref.

html
<wd-video-preview ref="videoPreviewRef" />
<wd-button @click="openPreview">Open Preview</wd-button>
ts
import { ref } from 'vue'
import type { VideoPreviewInstance, PreviewVideo } from '@/uni_modules/wot-ui/components/wd-video-preview/types'

const videoPreviewRef = ref<VideoPreviewInstance>()

const video: PreviewVideo = {
  url: 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4',
  poster: 'https://wot-ui.cn/assets/panda.jpg',
  title: 'Video Preview'
}

function openPreview() {
  videoPreviewRef.value?.open(video)
}

VideoPreview Attributes ​

ParameterDescriptionTypeDefault Value
selectorInstance identifier, used to distinguish multiple video preview instancesstring''
z-indexPreview z-indexnumber1000
full-screenWhether to use fullscreen previewbooleanfalse
close-positionClose button position, optional values are left-top and right-topstringleft-top
on-openCallback when component opens() => void-
on-closeCallback when component closes() => void-
custom-styleCustom root node stylestring''
custom-classCustom root node style classstring''

VideoPreview Events ​

Event NameDescriptionParameters
openTriggered when opening preview-
closeTriggered when closing preview-

VideoPreview Methods ​

Call component instance methods through ref.

Method NameDescriptionParametersReturn Value
openOpen video previewvideo: VideoPreviewOptions-
closeClose video preview--

useVideoPreview ​

The basic usage, multi-instance calls, methods, and VideoPreviewOptions descriptions of useVideoPreview have been separately organized to useVideoPreview, and will not be repeated here in the component documentation.

主题定制 ​

CSS 变量 ​

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置。

名称默认值描述
--wot-video-preview-bg$opac-9_75预览背景色
--wot-video-preview-close-size$n-24关闭图标尺寸
--wot-video-preview-close-color$icon-white关闭图标颜色
--wot-video-preview-close-margin$spacing-extra-loose关闭按钮外边距
--wot-video-preview-video-height$n-248视频预览区域高度
--wot-video-preview-z-index1000预览层级
--wot-video-preview-close-z-index10关闭按钮层级

Source Code ​

Documentation
• Component

Released under the MIT License.

Released under the MIT License.