本篇是星星评分部分,先上代码:

1.header.vue:

<template>
  <transition name="fade">
            <div v-show="detailShow" class="detail">
                <div class="detail-wrapper clearfix">
                    <div class="detail-main">
                        <h1 class="name">{{seller.name}}</h1>
                        <div class="star-wrapper">
                            <star :size="48" :score = "seller.score"></star> <!--忽略其他,红色部分为星星评分有效代码,这里是使用星星组件,并且这里绑定了size和score,使得在star.vue里也能取到。
                        </div>
                        <div class="title">
                            <div class="line"></div>
                            <div class="text">优惠信息</div>
                            <div class="line"></div>
                        </div>
                        <ul v-if="seller.supports" class="supports">
                            <li class="support-item" v-for="(item,index) in seller.supports">
                                <span class="icon" :class="classMap[seller.supports[index].type]"></span>
                                <span class="text">{{seller.supports[index].description}}</span>
                            </li>
                        </ul>
                        <div class="title">
                            <div class="line"></div>
                            <div class="text">商家公告</div>
                            <div class="line"></div>
                        </div>
                        <div class="bulletin">
                            <p class="content">{{seller.bulletin}}</p>
                        </div>
                    </div>
                </div>
                <div class="detail-close" @click="hideDetail">
                    <i class="icon-close">*</i>
                </div>
            </div>
        </transition>
</template>
<script>
import star from 'components/star/star'
; <!-----忽略其他,红色部分为星星评分有效代码,这里是引入星星组件
export default{
props:{
seller:{
type:Object
}
},
data(){
return {
detailShow:false
};
},
methods:{
showDetail(){
this.detailShow = true;
},
hideDetail(){
this.detailShow = false;
}
},
created() {
this.classMap = ['decrease','discount','special','invoice','guarantee'];
},
components:{ <!-----忽略其他,红色部分为星星评分有效代码,这里加入星星组件作为header的子组件。
star
}

}
</script>

2.star.vue:

<template>
<div class="star" :class="starType">
<span v-for="itemClass in itemClasses" :class="itemClass" class="star-item" track-by ="$index"></span>
<!-- v-for="(itemClass,index) in itemClasses" -->
</div>
</template>
<script>
const LENGTH = 5;
const CLS_ON = 'on';
const CLS_HALF = 'half';
const CLS_OFF = 'off';
export default{
props:{
size:{
type:Number
},
score:{
type:Number
}
},
computed:{
starType(){
return 'star-'+this.size;
},
itemClasses(){
let result = [];
let score = Math.floor(this.score *2) /2;// 通过分数算星星个数
// 向下取0.5的公式。floor() 执行向下取整
// floor(3.3 * 2) / 2 = 3 即 3颗全星+2颗无星
// floor(3.6 * 2) / 2 = 3.5 即 3颗全星+1颗半星+1颗无星
let hasDecimal = score % 1 !== 0;// 取余不为0则有半星
let integer = Math.floor(score);// 整数部分
for(let i=0;i<integer;i++){// 设置全星
result.push(CLS_ON);
}
if(hasDecimal){
result.push(CLS_HALF);
}
while(result.length < LENGTH){// 循环,补充无星
result.push(CLS_OFF);
}
return result;
}
}
}
</script>
<style lang='less'>
@import "../../common/style/mixin.less";
.star{
font-size:0;
.star-item{
display:inline-block;
background-repeat:no-repeat;
}
&.star-48{
.star-item{
width:20px;
height:20px;
margin-right:22px;
background-size:20px 20px;
&:last-child{
margin-right:0;
}
&.on{
.bg-image('star48_on')
}
&.half{
.bg-image('star48_half')
}
&.off{
.bg-image('star48_off')
}
}
}
&.star-36{
.star-item{
width:15px;
height:15px;
margin-right:6px;
background-size:15px 15px;
&:last-child{
margin-right:0;
}
&.on{
.bg-image('star36_on')
}
&.half{
.bg-image('star36_on')
}
&.off{
.bg-image('star36_on')
}
}
}
&.star-24{
.star-item{
width:10px;
height:10px;
margin-right:3px;
background-size:10px 10px;
&:last-child{
margin-right:0;
}
&.on{
.bg-image('star24_on')
}
&.half{
.bg-image('star24_on')
}
&.off{
.bg-image('star24_on')
}
}
}
}
</style>

vue2.0:(九)、外卖App弹窗部分星星评分的更多相关文章

  1. 项目vue2.0仿外卖APP(五)

    header组件 vue-resourse应用 https://github.com/pagekit/vue-resource vue-resource是Vue.js的一款插件,它可以通过XMLHtt ...

  2. 项目vue2.0仿外卖APP(六)

    goods 商品列表页开发 布局编写 除了商品之外还有购物车,还有个详情页,挺复杂的. 两栏布局:左侧固定宽度,右侧自适应,还是用flex. 因为内容可能会超过手机高度,超过就隐藏.左右两侧的内容是可 ...

  3. 项目vue2.0仿外卖APP(四)

    组件拆分 先把项目搭建时生成的代码给清了吧 现在static目录下引入reset.css 接着在index.html引入,并且设置<meta> 有时候呢,为了让代码符合我们平时的编码习惯, ...

  4. 项目vue2.0仿外卖APP(一)

    最近用vue.js做一个仿饿了么外卖APP的项目,现在也把流程啊什么的暂时先整理一下在这个博客上面. 当然,这个过程会有点长,不过确实能学到很多东西. 话不多说,马上开始吧. 1.项目介绍 选用当前最 ...

  5. 项目vue2.0仿外卖APP(二)

    vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...

  6. 项目vue2.0仿外卖APP(七)

    ratings评价列表页实现 在ratings.vue组件里开发 首先先引入seller数据: 书写模板结构: 由于评价页又有之前写过的star.vue组件,所以又要在ratings.vue组件引入: ...

  7. 项目vue2.0仿外卖APP(三)

    项目的结构如下:                   项目资源准备 准备项目的各种图片资源等等 注意:在webpack可以不用css sprite,直接用单张图片,因为它会帮忙打包. 还有SVG图片, ...

  8. vue2.0:(八)、外卖App弹窗部分知识点总结

    本篇文章是对外卖App弹窗部分知识点的总结. 知识点一:如何从接口取出不同的图片. 答: 1.header.vue: 代码: <ul v-if="seller.supports&quo ...

  9. vue2.0:(八-2)、外卖App弹窗部分sticky footer

    什么是sticky-footer ? 如果页面内容不够长的时候,页脚块粘贴在视窗底部,如果内容足够长时,页脚块会被内容向下推送.那具体要怎么做呢?下面以外卖App为例: 第一种方法:这个自己用过,是好 ...

随机推荐

  1. 51nod 1443 路径和树——最短路生成树

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 不只是做一遍最短路.还要在可以选的边里选最短的才行. 以为是 ...

  2. Redis的Spring配置讲解

    Redis是一种特殊类型的数据库,他被称之为key-value存储 本文覆盖缓存和存储两方面进行说明,使用的是Spring 4.0和Java配置方式 代码地址下载地址:https://github.c ...

  3. Lagom学习 (二)

    以一个官方的例子,开启lagom的学习之旅. 1:   git clone https://github.com/lagom/activator-lagom-java-chirper.git. 2:  ...

  4. Poco 编译mysql

    POCO mysql需要自己添加connecter的header和lib MySQL Client: For the MySQL connector, the MySQL client librari ...

  5. JSON 生成 C# Model

    http://www.cnblogs.com/tianqiq/p/4309791.html

  6. POJ-3069

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10994   Accepted: 5555 D ...

  7. WPF PasswordBox鼠标进入时程序异常退出的解决办法

    最近在开发了一个程序中用到了PasswordBox控件,但是在程序给别人用的时候,鼠标一进入控件时程序就异常退出,查了下windows日志,错误显示如下: 应用程序: WpfPasswordTest2 ...

  8. setInterval(callbackfunc,time)中callbackfunc传参数问题

    var si=setInterval(callbackfunc,time)中callbackfunc传参数问题(循环执行) var st=setTimeout(callbackfunc,time);定 ...

  9. HDU - 6156 2017CCPC网络赛 Palindrome Function(数位dp找回文串)

    Palindrome Function As we all know,a palindrome number is the number which reads the same backward a ...

  10. sqlserver2012——EXISTS关键字

    1.返回TRUE或者FALSE 如果exists查询存在,则能查询出来 select a.* From 成绩信息 a ’) 2.判断用户登录 ) ) ' set @pwd='xxxxxxx' if e ...