Home Web Front-end Vue.js VUE3 Getting Started Example: Making a Simple Video Player

VUE3 Getting Started Example: Making a Simple Video Player

Jun 15, 2023 pm 09:42 PM
vue Example video player

With the continuous emergence of new generation front-end frameworks, VUE3 is highly loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player.

1. Install VUE3

First, we need to install VUE3 locally. Open the command line tool and execute the following command:

npm install vue@next

Then, create a new HTML file and introduce VUE3:

<!doctype html>
<html>
<head>
    <title>VUE3视频播放器</title>
</head>
<body>
    <div id="app">
        <video src="" controls></video>
    </div>
    <script type="module">
        import {createApp} from 'vue';

        const app = createApp({
            data() {
                return {
                    videoSrc: ''
                };
            },

            methods: {
                playVideo() {
                    this.$refs.video.play();
                },

                pauseVideo() {
                    this.$refs.video.pause();
                }
            }
        });

        app.mount('#app');
    </script>
</body>
</html>

This code first introduces VUE3 and creates an app named "app" root node. Among them,

  • videoSrc is used to store the path of the video
  • The playVideo method is used to play the video
  • ThepauseVideo method is used to pause the video

2. Binding data

In this example, we will use v-model to bind the value of the `` tag to videoSrc so that we can change the video path by setting the value of the input box. We can also use v-bind to bind the src attribute of the video tag to videoSrc:

<div>
    <input v-model="videoSrc" type="text" placeholder="在这里输入视频地址" />
    <br />
    <br />
    <video ref="video" v-bind:src="videoSrc" controls></video>
</div>

Here, we bind the data to an input box and bind the video path to the video tag.

3. Add Control Buttons

Next, we add two event listeners that allow us to add control buttons on the page - one for playing the video and one for pausing the video. .

<div>
    <input v-model="videoSrc" type="text" placeholder="在这里输入视频地址" />
    <br />
    <br />
    <video ref="video" v-bind:src="videoSrc" controls></video>
    <br />
    <br />
    <button v-on:click="playVideo()">播放</button>
    <button v-on:click="pauseVideo()">暂停</button>
</div>

4. Summary

Now, we have built a simple VUE3 video player. Through this simple example, you have learned about the basic data binding of VUE3 and how to bind and control the video tag. From this foundation, you can delve deeper into VUE3 and apply it to richer applications.

The emergence of VUE3 allows front-end engineers to get rid of some tedious operations and processes, greatly improving development efficiency. Hope this article is helpful to you.

The above is the detailed content of VUE3 Getting Started Example: Making a Simple Video Player. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
What is the significance of Vue's reactivity transform (experimental, then removed) and its goals? What is the significance of Vue's reactivity transform (experimental, then removed) and its goals? Jun 20, 2025 am 01:01 AM

ReactivitytransforminVue3aimedtosimplifyhandlingreactivedatabyautomaticallytrackingandmanagingreactivitywithoutrequiringmanualref()or.valueusage.Itsoughttoreduceboilerplateandimprovecodereadabilitybytreatingvariableslikeletandconstasautomaticallyreac

Bilibili domestic video entrance Bilibili domestic video entry Bilibili domestic video entrance Bilibili domestic video entry Jun 04, 2025 pm 05:03 PM

As a diversified video platform, B station provides users with rich domestic blockbuster resources. Through the steps introduced in this article, users can easily enter the domestic blockbuster video entrance of B station and enjoy a high-quality viewing experience. Whether you are a film and television enthusiast or want to watch a movie occasionally to relax, Bilibili can meet your needs. I hope this article can help you better utilize the domestic blockbuster resources of B station and enjoy unlimited film and television fun.

Ranking of the players that can watch movies and TV for free online movies and TV shows recommended ten players that can watch movies and TV shows for free online movies and TV shows Ranking of the players that can watch movies and TV for free online movies and TV shows recommended ten players that can watch movies and TV shows for free online movies and TV shows Jun 04, 2025 pm 05:54 PM

Ten players that can watch movies and TV online for free include: 1. iQiyi, providing rich high-definition video content; 2. Tencent Video, massive film and TV resources and multi-platform synchronization; 3. Youku Video, covering a wide range of film and TV and vertical content; 4. Mango TV, Hunan Satellite TV has rich program resources; 5. Sohu Video, supporting multi-format playback and multi-language subtitles; 6. CBox CCTV Video, free to watch central and local TV programs; 7. Thunder Video, supporting multi-function playback and download; 8. Everyone watches super fast movies and TV, pure and ad-free, fast playback; 9. AcFun, suitable for two-dimensional culture enthusiasts; 10. Bilibili, providing high-definition barrage video experience.

How can internationalization (i18n) and localization (l10n) be implemented in a Vue application? How can internationalization (i18n) and localization (l10n) be implemented in a Vue application? Jun 20, 2025 am 01:00 AM

InternationalizationandlocalizationinVueappsareprimarilyhandledusingtheVueI18nplugin.1.Installvue-i18nvianpmoryarn.2.CreatelocaleJSONfiles(e.g.,en.json,es.json)fortranslationmessages.3.Setupthei18ninstanceinmain.jswithlocaleconfigurationandmessagefil

What are the benefits of using key attributes (:key) with v-for directives in Vue? What are the benefits of using key attributes (:key) with v-for directives in Vue? Jun 08, 2025 am 12:14 AM

Usingthe:keyattributewithv-forinVueisessentialforperformanceandcorrectbehavior.First,ithelpsVuetrackeachelementefficientlybyenablingthevirtualDOMdiffingalgorithmtoidentifyandupdateonlywhat’snecessary.Second,itpreservescomponentstateinsideloops,ensuri

How can you optimize the re-rendering of large lists or complex components in Vue? How can you optimize the re-rendering of large lists or complex components in Vue? Jun 07, 2025 am 12:14 AM

Methods to optimize the performance of large lists and complex components in Vue include: 1. Use the v-once directive to process static content to reduce unnecessary updates; 2. implement virtual scrolling and render only the content of the visual area, such as using the vue-virtual-scroller library; 3. Cache components through keep-alive or v-once to avoid duplicate mounts; 4. Use computed properties and listeners to optimize responsive logic to reduce the re-rendering range; 5. Follow best practices, such as using unique keys in v-for, avoiding inline functions in templates, and using performance analysis tools to locate bottlenecks. These strategies can effectively improve application fluency.

What is server side rendering SSR in Vue? What is server side rendering SSR in Vue? Jun 25, 2025 am 12:49 AM

Server-siderendering(SSR)inVueimprovesperformanceandSEObygeneratingHTMLontheserver.1.TheserverrunsVueappcodeandgeneratesHTMLbasedonthecurrentroute.2.ThatHTMLissenttothebrowserimmediately.3.Vuehydratesthepage,attachingeventlistenerstomakeitinteractive

How can v-model be used for two-way data binding on custom components in Vue? How can v-model be used for two-way data binding on custom components in Vue? Jun 06, 2025 am 11:41 AM

To use v-model to implement two-way binding of custom components in Vue, you must first understand its working mechanism. For custom components, you need: 1. Receive a prop named modelValue; 2. Trigger an event named update:modelValue. By default, it will be parsed to, so the component needs to use:value="modelValue" and $emit('update:modelValue') to synchronize the data. In addition, the prop and event names can be customized via model:{prop:'checked',event:'change'}, which are suitable for different types of components such as switches

See all articles