Vue makes a simple random roll call

Vue makes a simple random roll call

Layout part:

<div id="app">
        <p>{{result}}</p>
        <button @click="randomName()">{{txt}}</button>
    </div>


Vue part:

 <script>
        let vm = new Vue({
            el:'#app',
            data:{
                list:["Xiaoyi","Lier","Wangsan","Saturday","Zhangwu"],
                // Randomly named content result:'',
                //Button text content txt: "Start roll call",
                // Process control switch open: true,
                // Define the timer switch timer:null
            },
            methods: {
                move(){
                    // Get a random number between 0 and the length of the current array let random = Math.floor(Math.random()*(this.list.length-0))
 
                    // Let the random number become the random subscript of the list array, assign it to result, and render it on the page this.result = this.list[random]
                },
                randomName(){
                    // Process control switch if(this.open){
                        // Define the timer and call the move method this.timer = setInterval(this.move,100)
                        this.txt = "Stop calling names"
                        this.open = false
                    }else{
                        // Clear the timer clearInterval(this.timer)
                        this.txt = "Start roll call"
                        this.open = true
                    }
                }
            }
        })
    </script>


View the results:

This is the end of this article about making a simple random roll call with Vue. For more information about making a random roll call with Vue, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  How to hide the text in the a tag and display the image? Compatible with 360 mode rendering

>>:  Analysis of MySQL example DTID master-slave principle

Recommend

Mysql master-slave synchronization Last_IO_Errno:1236 error solution

What is the reason for the Last_IO_Errno:1236 err...

Solution to Docker disk space cleaning

Some time ago, I encountered the problem that the...

How to detect Ubuntu version using command line

Method 1: Use the lsb_release utility The lsb_rel...

What are the benefits of using B+ tree as index structure in MySQL?

Preface In MySQL, both Innodb and MyIsam use B+ t...

A brief analysis of the usage of HTML float

Some usage of float Left suspension: float:left; ...

Quickly solve the problem of slow and stuck opening of input[type=file]

Why is it that when the input tag type is file an...

Detailed example of changing Linux account password

Change personal account password If ordinary user...

Tutorial on installing mysql5.7.36 database in Linux environment

Download address: https://dev.mysql.com/downloads...

A simple tutorial on how to use the mysql log system

Table of contents Preface 1. Error log 2. Binary ...

MySQL 8.0.15 installation and configuration tutorial under Win10

What I have been learning recently involves knowl...

Detailed explanation of MySQL deadlock and database and table sharding issues

Record the problem points of MySQL production. Bu...

JavaScript Canvas draws dynamic wireframe effect

This article shares the specific code of JavaScri...