Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Vue to make a simple random click list

Shulou Source: shulou.com Published: 2022-06-02 08:26:44 10月02日 Update

This article introduces the knowledge of "how to use Vue to make a simple random click roster". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Layout section:

{{result}}

{{txt}}

Vue section:

Let vm = new Vue ({el:'#app', data: {list: ["Primary one", "Li er", "Wang San", "Thursday", "Zhang Wu"], / / random roll call content result:'', / / button text content txt: "roll call" / / flow control switch open:true, / / define timer switch timer:null} Methods: {move () {/ / get a random number of 0-the current array length let random = Math.floor (Math.random () * (this.list.length-0)) / / make the random number the random subscript of the list array Assign value to result, render this.result = this.list [random]} on the page, randomName () {/ / flow control switch if (this.open) {/ / define timer Call the move method this.timer = setInterval (this.move This.txt = "stop roll call" this.open = false} else {/ / clear timer clearInterval (this.timer) this.txt = "start roll call" This.open = true}) "how to use Vue to make a simple random click list" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Content timer count list array more process knowledge part random number control practical successful next subscript dilemma actual layout situation button text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL Docker vpn Huawei