Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize gradient progress bar by Vue

Shulou Source: shulou.com Published: 2022-05-31 19:22:09 09月22日 Update

This article mainly introduces "how to achieve gradient progress bar in Vue". In daily operation, I believe many people have doubts about how to achieve gradient progress bar in Vue. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve gradient progress bar in Vue". Next, please follow the editor to study!

Functional requirements

The total grid number of the progress bar can be customized.

The proportion of the current number of pieces corresponds to the current number of blue squares

The blue gradient of the lattice should conform to the UI design.

First determine the value in props, that is, the value that the component needs to receive.

There are only names, totals, and current values

Props: {name: {type:String, default: () = > ('data name')}, total: {type:Number, default: () = > (24)}, value: {type:Number, default: () = > (18)},}

Then there is the main implementation method, where a cubeCount is received as a parameter, that is, the total grid number needs to be defined.

Methods: {initStatus (cubeCount) {/ / 1. Get the width of the total grid number div let totalDomWidth=this.$refs.total.offsetWidth; / / 2. Calculate the ratio of the current grid let ratio= (this.value/this.total); / / 3. Calculate the width of each lattice let cubeWidth=Math.floor ((totalDomWidth/cubeCount)-1);},}

When calculating the width of each grid, Math.floor is used to round down. As for the following-1, it is the spacing between the grids.

Then, according to the width of each grid and the number of grids, the total lattice is dynamically generated and inserted into the div.

For (let ionome0), data () {return {};}, mounted () {let that=this this.initStatus (16);}, updated () {this.initStatus (16);}, methods: {initStatus (cubeCount) {let that=this; let totalDomWidth=this.$refs.total.offsetWidth Let ratio= (this.value/this.total); let cubeWidth=Math.floor ((totalDomWidth/cubeCount)-1); let cubeDomArr; for (let iTuno)

Tags: Grid color progress discoloration width learning name difference that is data array method more ratio component chromatic aberration blue help practical headache Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple macOS Xiaomi Linux