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
What is the reason for the Last_IO_Errno:1236 err...
Web page encoding is translated into English as we...
I developed a project some time ago. I used the f...
I wrote this blog to remember that I just install...
Some time ago, I encountered the problem that the...
Method 1: Use the lsb_release utility The lsb_rel...
Preface In MySQL, both Innodb and MyIsam use B+ t...
Some usage of float Left suspension: float:left; ...
Why is it that when the input tag type is file an...
Change personal account password If ordinary user...
Download address: https://dev.mysql.com/downloads...
Table of contents Preface 1. Error log 2. Binary ...
What I have been learning recently involves knowl...
Record the problem points of MySQL production. Bu...
This article shares the specific code of JavaScri...