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
This article example shares the specific code of ...
environment Hostname IP address Serve Prometheus ...
Table of contents 1. Installation 2. Import in ma...
This article summarizes some simple principles of...
Enough of small talk <br />Based on the lar...
3D coordinate concept When an element rotates, it...
How to change the image hyperlink when the mouse p...
When using the idea development tool to debug cod...
Table of contents 1. Mysql data structure 2. The ...
On Linux, bash is adopted as the standard, which ...
Preface Two types of swap space can be created un...
The pitfalls 1. Many tutorials on the Internet wr...
The link-in style is to put all the styles in one...
This article introduces Online preview and downlo...
Table of contents 1. Introduction 2. Principle II...