Skip to content

Barrage - Vant 4

Barrage

🎬 Ready to bring your videos to life with flying comments? Let's explore the Barrage component!

Intro 📖

Create an immersive video experience with scrolling comments that flow across the screen! 💬✨ Perfect for live streams, video platforms, or any interactive content where user engagement takes center stage! 🚀

⚠️ Note: Please upgrade vant to >= v4.4.0 before using this awesome component!

Install 📦

Let's get the party started! Register the component globally via app.use - it's that simple! 🎯 Check out our Component Registration guide for more installation options.

js
import { createApp } from'vue'; import { Barrage } from'vant'; const app = createApp(); app.use(Barrage);

Usage 🎮

Basic Usage ⚡

Watch the magic happen! Comments will flow across the screen like a digital river of thoughts! 🌊

html
ts
exportdefault { setup() { const defaultList = [ { id: 100, text: 'Lightweight' }, { id: 101, text: 'Customizable' }, { id: 102, text: 'Mobile' }, { id: 103, text: 'Vue' }, { id: 104, text: 'Library' }, { id: 105, text: 'VantUI' }, { id: 106, text: '666' }, ]; const list = ref([...defaultList]); constadd = () => { list.value.push({ id: Math.random(), text: 'Barrage' }); }; return { list, add }; }, };

Imitate Video Barrage 🎥

Create a real video experience! Control playback with play/pause functionality - just like your favorite streaming platform! 🎮✨

html
ts
exportdefault { setup() { const defaultList = [ { id: 100, text: 'Lightweight' }, { id: 101, text: 'Customizable' }, { id: 102, text: 'Mobile' }, { id: 103, text: 'Vue' }, { id: 104, text: 'Library' }, { id: 105, text: 'VantUI' }, { id: 106, text: '666' }, ]; const list = ref([...defaultList]); const barrage = ref<BarrageInstance>(); constadd = () => { list.value.push({ id: Math.random(), text: 'Barrage' }); }; const [isPlay, toggle] = useToggle(false); watch(isPlay, () => { if (isPlay.value) barrage.value?.play(); else barrage.value?.pause(); }); return { list, barrage, isPlay, toggle, add }; }, };

API

Props

AttributeDescriptionTypeDefault
v-modelBarrage dataBarrageItem[]-
auto-playWhether to play the bullet screen automaticallybooleantrue
rowsThe number of lines of text*numberstring*
topSpacing between the top of the barrage area, unit px*numberstring*
durationText animation duration, unit ms*numberstring*
delayBarrage animation delay, unit msnumber300

Methods

Use ref to get Barrage instance and call instance methods.

NameDescriptionAttributeReturn value
playPlay barrage--
pausePause barrage--

Slots

NameDescription
defaultDefault slot

Types

The component exports the following type definitions:

ts
importtype { BarrageProps, BarrageItem, BarrageInstance } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-barrage-font-size16px-
--van-barrage-space10px-
--van-barrage-colorvar(--van-white)-
--van-barrage-fontinherit-

Enterprise-level mobile solution based on Vant