显示评分和打分组件,可现实半颗星星效果

效果图:

参数名 类型 说明
score Number 分数 ,默认0,保留一位小数
disabled Boolean 是否只读,默认false,鼠标点击可以打分
showText Boolean 是否显示分数,默认false
<!--评分-->
<template>
<div class="rate" :class="{'disabled':disabled}">
<i v-for="i in 5" class="iconfont" @mouseenter="disabled?'':curScore=i" @mouseleave="disabled?'':curScore=''" @click="disabled?'':setScore(i)" :class="getClass(i)">
<i v-if="disabled&&i==Math.floor(score)+1" class="iconfont icon-star" :style="'width:'+width"></i>
</i>
<span v-if="showText" class="text">{{curScore||score}}分</span>
</div>
</template> <script>
export default {
name:'MyRate',
props: {
score: {
type: Number,
default: 0,
//required: true
},
disabled: {
type: Boolean,
default: false,
},
showText: {
type: Boolean,
default: false,
},
},
data() {
return {
curScore: '',
width:'',
}
},
created: function () {
this.getDecimal();
},
methods: {
getClass(i) {
if (this.curScore === '') {
return i <= this.score ? 'icon-star' : 'icon-star-o'
} else {
return i <= this.curScore ? 'icon-star' : 'icon-star-o'
}
},
getDecimal() {
this.width=Number(this.score * 100 - Math.floor(this.score) * 100)+'%';
},
setScore(i){
this.$emit('update:score',i);//使用`.sync`修饰符,对score 进行“双向绑定
}
}
}
</script>

//页面中调用

  只读,不显示数字:<my-rate :score="1.5" disabled/>
只读,显示数字:<my-rate :score="3.6" disabled showText/>
鼠标点击评分,显示数字:<my-rate :score.sync="curScore" showText/>
<button @click="submit">提交</button>
//submit(){alert(this.curScore);} 提交显示分数

vue 星星评分组件的更多相关文章

  1. vue星级评分组件

    <template> <div class="Rating-gray"> <i v-for="(item,index) in itemCla ...

  2. Full-featured Vue 评分组件

    分享一下最近写的 vue 的评分组件 Features: 支持半星.可清除.文案展示.只读.自定义颜色.自定义字符及图片等.支持 hover 的时候改变 value.内置三种样式,以及非常好看 DEM ...

  3. vue2.0:(九)、外卖App弹窗部分星星评分

    本篇是星星评分部分,先上代码: 1.header.vue: <template> <transition name="fade">            & ...

  4. 干货之运用CALayer创建星级评分组件(五角星)

    本篇记录星级评分组件的创建过程以及CALayer的运用. 为了实现一个星级评分的组件,使用了CALayer,涉及到mask.CGPathRef.UIBezierPath.动画和一个计算多角星关键节点的 ...

  5. vue.js之组件(上篇)

    本文的Demo和源代码已放到GitHub,如果您觉得本篇内容不错,请点个赞,或在GitHub上加个星星! https://github.com/zwl-jasmine95/Vue_test 以下所有知 ...

  6. Angular 星级评分组件

    一.需求演变及描述: 1. 有一个“客户对公司的总体评价”的字段(evalutation).字段为枚举类型,0-5,对应关系为:0-暂无评价,1-很差,2-差,3-一般,4-好,5-很好 2. 后来需 ...

  7. JS原生评分组件

    JS原生评分组件 <html> <head> <meta http-equiv="Content-Type" content="text/h ...

  8. Vue 2.0 组件库总结

    UI组件 element - 饿了么出品的Vue2的web UI工具套件 Vux - 基于Vue和WeUI的组件库 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开 ...

  9. 【CSS】329- 非常强!3行核心css代码的rate评分组件

    像rate评分组件一般都用javascript写,所以这次将是一个全新的尝试,用css实现一个rate评分 ❗ 核心代码也就三行? 01 效果图 02 原理 主要是借助radio单选框,梳理如下: 去 ...

随机推荐

  1. Coderfroces 864 D. Make a Permutation!

    D. Make a Permutation! Ivan has an array consisting of n elements. Each of the elements is an intege ...

  2. Callback<> and Bind()

    Callback<> and Bind() Introduction The templated base::Callback<> class is a generalized ...

  3. SP1026 FAVDICE - Favorite Dice 数学期望

    题目描述: 一个n面的骰子,求期望掷几次能使得每一面都被掷到. 题解:先谈一下期望DP. 一般地,如果终止状态固定,我们都会选择逆序计算. 很多题目如果顺序计算会出现有分母为 0 的情况,而逆序计算中 ...

  4. Python3爬虫之爬取某一路径的所有html文件

    要离线下载易百教程网站中的所有关于Python的教程,需要将Python教程的首页作为种子url:http://www.yiibai.com/python/,然后按照广度优先(广度优先,使用队列:深度 ...

  5. 思科2960trunk vlan配置及路由IP配置

    en conf t vlan id end conf t inter rang gi 0/0/1-x switchport access vlan id no shutdown exit (confi ...

  6. pyspark使用

    1.安装python3 2.idea安装Python插件 3.下载spark,设置SPARK_HOME环境变量 4.安装pyspark,numpy 5.运行pyspark应用 pyspark应用如果使 ...

  7. 「HAOI2016」字符合并

    「HAOI2016」字符合并 题意: ​ 有一个长度为\(n\)的\(01\)串,你可以每次将相邻的\(k\)个字符合并,得到一个新的字符并获得一定分数.得到的新字符和分数由这\(k\)个字符确定.你 ...

  8. linux 查找文件和文件夹与下载命令

    查找命令: 查找根目录下查找文件夹名称叫dir的目录地址 find / -name dir  -d 查找/var/www/目录下叫index.jsp的文件 find /var/www/ -name i ...

  9. 今日SGU 5.5

    SGU 114 题意:求一个点到其他点的距离总和最小,距离的定义是x轴距离乘以那个点的人数p 收获:带权中位数,按坐标排序,然后扫一遍,最后权值超过或等于总权值的一半时的那个点就是答案,证明暂无 #i ...

  10. UVALive 5292 Critical Links

    Critical Links Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...