This article shares the specific code of Vue to implement star rating with decimal points for your reference. The specific content is as follows First we need to import the vue.js file CSS part <style> main{ position:relative; } .star_line{ /* Set to force no line break */ width-space:nowrap; overflow: hidden; position: absolute; } .star{ display: inline-block; /* Set the mouse to turn into a small hand style when it is placed on a star*/ cursor: pointer } </style> Body <div id="app"> <input type="text" v-model.number="score"> <- When any component receives the bound value in a two-way binding, it must use value to receive it. The principle is as follows: input -> <v-star v-model="score"></v-star> </div> In the js part, we use components, input is in the root component, and the stars we created are placed in a component. The star rating is mainly realized through two-way binding, where the parent component and the child component pass values to each other. Component template part <script id="v-star" type="text/html"> <main :style="mainStyle"> <!-- White Star --> <div class="star_line"> <span @click="changeValue(star)" class="star" :style="starStyle" v-for="star in total">☆</span> </div> <!-- Black Star --> <div class="star_line" :style="blackStyle"> <span @click="changeValue(star-1)" class="star" :style="starStyle" v-for="star in total">★</span> </div> </main> </script> js part <script> Vue.component("v-star",{ template:"#v-star", props:{ total:{ default:10, }, size:{ default:30 }, // Receive the score passed from the parent component value:{} }, // Computed properties computed:{ mainStyle(){ return { width:this.size * this.total + "px", } }, starStyle(){ return { width:this.size + "px", height:this.size + "px", fontSize: this.size + 6 + "px" } }, blackStyle(){ return { width:this.value / this.total * 100 + "%" } } }, methods:{ changeValue(value){ // Pass the latest result to input // The input tag has a default input event this.$emit("input",value) } } }) new Vue({ el:"#app", data:{ score:1 } }) </script> Rendering The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: CentOS 7 Forgot Password Solution Process Diagram
>>: Troubleshooting of master-slave delay issues when upgrading MySQL 5.6 to 5.7
MySQL will automatically create a database named ...
This article mainly introduces how to call desktop...
The following functions are implemented: 1. Usern...
1. Copy the configuration file to the user enviro...
Table of contents Table/index.js Table/model/inde...
The custom encapsulation code of the vue button c...
Platform deployment 1. Install JDK step1. Downloa...
When making a form in a recent project, I need to...
1. Two ways to specify the character set of the h...
The one I wrote before is too complicated, let’s ...
This article example shares the specific code of ...
When installing packages on an Ubuntu server, you...
This article mainly introduces the differences be...
During system maintenance, you may need to check ...
Web page WB.ExecWB control printing method Copy c...