Vue dynamically achieves scoring results and vue dynamic scoring

Source: Internet
Author: User

Vue dynamically achieves scoring results and vue dynamic scoring

The examples in this article share with you the specific code for Vue to dynamically achieve the scoring effect for your reference. The specific content is as follows:

1. There are three types of images:

On: half: off

<style>  .star{    font-size: 0;  }  .star-item{    display: inline-block;    background-repeat: no-repeat;    width: 20px;    height: 20px;    margin-right: 22px;    background-size: 100%;  }  .star-item.on{    background-image: url(img/on.png);  }  .star-item.half{    background-image: url(img/half.png);  }  .star-item.off{    background-image: url(img/off.png);  }</style>
<Div id = "app"> <ul class = "star"> <span v-for = "(itemClass, index) in itemClasses ": class = "itemClass" class = "star-item" track-by = "index"> </span> <! -- Performance Optimization track-by data will not be re-rendered without changing --> </ul> </div>
<Script> new Vue ({el: '# app', data: {score: 4}, computed: {// calculation attribute itemClasses () {let result = []; let score = Math. floor (this. score * 2)/2; let hasDecimal = score % 1! = 0; let integer = Math. floor (score); for (let I = 0; I <integer; I ++) {result. push ("on");} if (hasDecimal) {result. push ("half");} while (result. length <5) {result. push ("off") ;}return result ;}}) </script>

Change code as needed

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.