vue2.0:(九)、外卖App弹窗部分星星评分
本篇是星星评分部分,先上代码:
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弹窗部分星星评分的更多相关文章
- 项目vue2.0仿外卖APP(五)
header组件 vue-resourse应用 https://github.com/pagekit/vue-resource vue-resource是Vue.js的一款插件,它可以通过XMLHtt ...
- 项目vue2.0仿外卖APP(六)
goods 商品列表页开发 布局编写 除了商品之外还有购物车,还有个详情页,挺复杂的. 两栏布局:左侧固定宽度,右侧自适应,还是用flex. 因为内容可能会超过手机高度,超过就隐藏.左右两侧的内容是可 ...
- 项目vue2.0仿外卖APP(四)
组件拆分 先把项目搭建时生成的代码给清了吧 现在static目录下引入reset.css 接着在index.html引入,并且设置<meta> 有时候呢,为了让代码符合我们平时的编码习惯, ...
- 项目vue2.0仿外卖APP(一)
最近用vue.js做一个仿饿了么外卖APP的项目,现在也把流程啊什么的暂时先整理一下在这个博客上面. 当然,这个过程会有点长,不过确实能学到很多东西. 话不多说,马上开始吧. 1.项目介绍 选用当前最 ...
- 项目vue2.0仿外卖APP(二)
vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...
- 项目vue2.0仿外卖APP(七)
ratings评价列表页实现 在ratings.vue组件里开发 首先先引入seller数据: 书写模板结构: 由于评价页又有之前写过的star.vue组件,所以又要在ratings.vue组件引入: ...
- 项目vue2.0仿外卖APP(三)
项目的结构如下: 项目资源准备 准备项目的各种图片资源等等 注意:在webpack可以不用css sprite,直接用单张图片,因为它会帮忙打包. 还有SVG图片, ...
- vue2.0:(八)、外卖App弹窗部分知识点总结
本篇文章是对外卖App弹窗部分知识点的总结. 知识点一:如何从接口取出不同的图片. 答: 1.header.vue: 代码: <ul v-if="seller.supports&quo ...
- vue2.0:(八-2)、外卖App弹窗部分sticky footer
什么是sticky-footer ? 如果页面内容不够长的时候,页脚块粘贴在视窗底部,如果内容足够长时,页脚块会被内容向下推送.那具体要怎么做呢?下面以外卖App为例: 第一种方法:这个自己用过,是好 ...
随机推荐
- 洛谷 1979 华容道——最短路+dp
题目:https://www.luogu.org/problemnew/show/P1979 感到无从下手.但不妨用dp的角度来看.因为空格只有在指定棋子的旁边才有用,所以状态记成制定棋子的位置与空格 ...
- makefile 使用【转载】
该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客: http://blog.csdn.net/haoel/article/details/2886 makefile很重 ...
- linux 安装SSH Server + FTP Server(openssh-server + vsftp)
openssh-server (推荐. 一般ssh,ftp 都是单独的,但是这个包含2个) 默认ubuntu 已经安装了, ssh client ,ftp client dpkg -l | grep ...
- static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCmdTarget::* )(NMHDR *,LRESULT
static_cast” : 无法从“void (__thiscall CMainFrame::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCm ...
- JavaScript高级程序设计学习笔记第一章
作为学习javascript的小白,为了督促自己读书,写下自己在读书时的提炼的关键点. 第一章: 1.JavaScript简史:Netscape Navigator中的JavaScript与Inter ...
- Oracle内置函数大全(转)
SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- gulp --watch直接退出,并没有监听
1.在es6(彩票项目)搭建环境时遇到gulp --watch 只运行一次就退出了不能监听: D:\nodejs\es6-base>gulp --watch [::] Failed to loa ...
- ubuntu18.04安装配置opencv3.4.0
1.安装配置相关工具及依赖库 sudo apt-get install build-essential # 必须的,gcc编译环境 sudo apt-get install cmake git lib ...