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

js canvas realizes slider verification

This article example shares the specific code of ...

Practical solution for Prometheus container deployment

environment Hostname IP address Serve Prometheus ...

Detailed explanation of how to use element-plus in Vue3

Table of contents 1. Installation 2. Import in ma...

Simple principles for web page layout design

This article summarizes some simple principles of...

Page Refactoring Skills - Content

Enough of small talk <br />Based on the lar...

Detailed explanation of CSS3 rotating cube problem

3D coordinate concept When an element rotates, it...

Why is the disk space still occupied after deleting table data in MySQL?

Table of contents 1. Mysql data structure 2. The ...

Detailed explanation of bash command usage

On Linux, bash is adopted as the standard, which ...

Summary of five commands to check swap space in Linux

Preface Two types of swap space can be created un...

MySQL 8.0.15 version installation tutorial connect to Navicat.list

The pitfalls 1. Many tutorials on the Internet wr...

How to import CSS styles into HTML external style sheets

The link-in style is to put all the styles in one...

Example code for circular hover effect using CSS Transitions

This article introduces Online preview and downlo...

An article to understand what is MySQL Index Pushdown (ICP)

Table of contents 1. Introduction 2. Principle II...